Author Topic: I want to initialize the following values after selection, but an error occurs.  (Read 2568 times)

ohbayashi

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 41
    • View Profile
I want to initialize the following values after selection, but an error occurs.
Please tell me if there is a simple initialization method.

Code: [Select]
{ title: "address", align: "center", colModel: [
    { title: "prefecture", dataIndx: "prefecture", dataType: "string", minWidth: 140,
      editor: {
          type: "select",
          labelIndx: "prefecture",
          valueIndx: "prefecture",
          options: function (ui) {
              var keys = [],
                  opts = [];
              zipcodes.forEach(function(row) {
                  if (keys.indexOf(row.prefecture) < 0) {
                      keys.push(row.prefecture);
//                      opts.push({ prefecture: row.prefecture, city: null, town: null, zip_code: null });    // Error:Uncaught incorrect usage of isValid dataIndx: city
                      opts.push({ prefecture: row.prefecture, city: 1, town: 2, zip_code: 3 });        // Appropriate value. This will not cause an error.
                  }
              })
              return opts;
          },
          dataMap: [ "prefecture", "city", "town", "zip_code" ]
      },
      validations: [
          { type: "minLen", value: 1, msg: "req." }
      ]

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Option keys may have null values, I don't see anything wrong in it. it can also be verified by entering null option keys in itemlist in this example: https://paramquery.com/pro/demos/datamap

The mentioned error is thrown elsewhere in your implementation. Could you please post a complete test case or a jsfiddle and mention the steps when the error is thrown.

Thanks

ohbayashi

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 41
    • View Profile
* colModel
Code: [Select]
            { title: "都道府県名", dataIndx: "prefecture", dataType: "string", minWidth: 140,
                filter: {
                    type: "select",
                    condition: "equal",
                    prepend: { "": "-- select --" },
                    options: [],
                },
                editor: {
                    type: "select",
                    labelIndx: "prefecture",
                    valueIndx: "prefecture",
                    options: [],
                    dataMap: [ "prefecture", "city", "town", "zip_code" ]
                },

* grid create.
Code: [Select]
            create: function (evt, ui) {
                // zipcodes load.
                let grid = this;
                $.ajax({
                    url: "/api/zipcodes/",
                    dataType: "json",
                })
                .then(  // 1:success, 2:error
                    function (response) {
                        zipcodes = response.zipcodes;
                    },
                    function () {
                        $("#err_result").text("Data acquisition failed.");
                    }
                )
                .then(
                    function () {
                        // prefecture option set.
                        let column = grid.getColumn({ dataIndx: "prefecture" }),
                            keys = [],
                            opts = [];
                        zipcodes.forEach(function(row) {
                            if (keys.indexOf(row.prefecture) < 0) {
                                keys.push(row.prefecture);
                                opts.push({ prefecture: row.prefecture, city: null, town: null, zip_code: null });
                                // opts.push({ prefecture: row.prefecture });
                            }
                        })
                        column.filter.options = keys;
                        column.editor.options = opts;
                    }

* console.log
Code: [Select]
Uncaught incorrect usage of isValid dataIndx: city
_piv.isValidCell @ pqgrid.dev.js:3979
_piv.isValid @ pqgrid.dev.js:4060
fn.isValid @ pqgrid.dev.js:4045
fn._digestData @ pqgrid.dev.js:5536
fnGrid.updateRow @ pqgrid.dev.js:13546
fn.saveEditCell @ pqgrid.dev.js:5419
(anonymous) @ pqgrid.dev.js:6142
dispatch @ jquery-1.8.3.min.js:2
u @ jquery-1.8.3.min.js:2
trigger @ jquery-1.8.3.min.js:2
(anonymous) @ jquery-1.8.3.min.js:2
each @ jquery-1.8.3.min.js:2
each @ jquery-1.8.3.min.js:2
trigger @ jquery-1.8.3.min.js:2
v.fn.(anonymous function) @ jquery-1.8.3.min.js:2
fn.blurEditor @ pqgrid.dev.js:5208
fn._onContMouseDown @ pqgrid.dev.js:4216
(anonymous) @ pqgrid.dev.js:2661
dispatch @ jquery-1.8.3.min.js:2
u @ jquery-1.8.3.min.js:2

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
It can only be guessed from the stack trace that error is related to the validations in your code. Your code is insufficient to reproduce the error. Kindly post a complete test case or a jsfiddle.