Author Topic: validation of multiple fields  (Read 2036 times)

ohbayashi

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 41
    • View Profile
validation of multiple fields
« on: May 23, 2017, 01:03:42 pm »
I would like to know the best way to do validation of multiple items.

# specification
1. "Judge"== false -> update NG

| flag0 | flag1 | judge |
|---|---|---|
| False | False | True |
| False | True | True |
| True | False | False |
| True | True | True |

# pattern 1
1. colModel validation
Code: [Select]
function validVisible(ui) {
    let col = ui.column,
        row = ui.rowData,
        flg0 = (col.dataIndx === "flag0" ? ui.value : row.flag0),
        flg1 = (col.dataIndx === "flag1" ? ui.value : row.flag1);
    if (flg0 === true && flg1 === false) {
        ui.msg = "error message!";
        return false;
    }
    return true;
}
let colMod = [
    { title: "flag0", dataIndx: "flag0", dataType: "bool", type: "checkbox",
      validations: [{ type: validVisible }]
    }),
    { title: "flag1", dataIndx: "flag1", dataType: "bool", type: "checkbox",
      validations: [{ type: validVisible }]
    }),

* The difficulty, this method leaves a message in one of the items.


# pattern 2
1. demo "Row Editing" - How to do with "update"

Code: [Select]
function update(rIndx, grid) {
    if (grid.saveEditCell() === false) { return false; }
    if (grid.isValid({ rowIndx: rIndx, focusInvalid: true }).valid === false) { return false; }

    // this.
    let row = grid.getRowData({ rowIndx: rIndx });
    if (row.flag0 === true && row.flag1 === false) {
        grid.focus({ rowIndxPage: rIndx, colIndx: 1 });
        return false;
    }
    :

* The difficulty, this method can not issue a message.


Please tell me if there is any other good way.
« Last Edit: May 23, 2017, 01:09:32 pm by ohbayashi »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: validation of multiple fields
« Reply #1 on: May 24, 2017, 11:24:06 am »
First one leaves a message and 2nd one doesn't leave a message.

your requirement is not clear enough to me. Can you please rephrase and clarify it.
« Last Edit: May 24, 2017, 11:26:51 am by paramquery »

ohbayashi

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: validation of multiple fields
« Reply #2 on: May 24, 2017, 04:30:28 pm »
Thank you. I solved it self-resolved.

Code: [Select]
function update(rIndx, grid) {
    if (grid.saveEditCell() === false) { return false; }
    if (grid.isValid({ rowIndx: rIndx, focusInvalid: true }).valid === false) { return false; }
    if ("validationMultiple" in grid.options) {
        if (grid.options.validationMultiple(rIndx, grid) === false) { return false; }
    }
    :

Code: [Select]
let gridObj =  {
        validationMultiple: function(rIndx, grid) {
            let row = grid.getRowData({ rowIndx: rIndx });
            if (row.visible_flag === true && row.pm_commit_flag === false) {
                $("#err_result").text("<< Error on update >>");
                $("#err_detail").text("err_message.  row:" + (rIndx + 1));
                return false;
            } else {
                $("#err_result").text("");
                $("#err_detail").text("");
            }
            return true;
        },
        :


let $grid = pq.grid("#gridMain", gridObj);