EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Don_Juan on February 20, 2018, 03:26:09 AM



Title: How to check all fields required are written?
Post by: Don_Juan on February 20, 2018, 03:26:09 AM
Hi,
exist a function or similar that allow me to check all fields required are written?
My fields are different from each other (combobox, validatebox,...), but almost all, have required=true  as inside option.
If the check is ok ,proceed to write, otherwise expose a allert message when i click a linkbutton (to save information) (I Want to check at the end).

I thought about this solution:
  • Scroll through all the elements by checking if required ! = Undefined
  • Check if the field is written.(if != Undefined)

Code:
var rows = $('#details').propertygrid('getChanges');
for(var i=0; i<rows.length; i++){
   if(rows[i].hasOwnProperty('editor')) {
      if(rows[i].editor.options.hasOwnProperty('required')) {
         if(rows[i].editor.options.required && (rows[i].value==""))
            console.log("Required, without value! ALLERT!!!!");
         else
            console.log("Requested and completed");
      } else
         console.log("I do not care");
   } else
      console.log("I do not care");
}

The values I get with $('#details').propertygrid ('getChanges') are:

0: {…}
    editor: {…}
        options: {…}
            missingMessage: "No Field!"
            required: true
            validType: Object { length: […] }
            __proto__: Object { … }
        type: "validatebox"
        __proto__: Object { … }
    group: "Dettagli"
    index: 0
    name: "Name"
    value: ""
    __proto__: Object { … }

.....
5: {…}
    editor: {…}
        options: {…}
            validType: Object { length: […] }
            __proto__: Object { … }
        type: "validatebox"
        __proto__: Object { … }
    group: "Dettagli"
    index: 5
    name: "Tag"
    value: ""
....

Is there another way?
Thanks!


Title: Re: How to check all fields required are written?
Post by: proceno72 on February 20, 2018, 07:23:41 AM
Are you talking about form fields? If so it'simple; you can try "validate" action of EasyUi form component


Title: Re: How to check all fields required are written?
Post by: Don_Juan on February 21, 2018, 01:08:21 AM
I used a propertygrid into window.