Select to view content in your preferred language

Validation Text Box

1608
2
Jump to solution
04-02-2011 02:36 PM
JosephSaltenberger
Deactivated User
Hi,

I have implemented the validation text box for the editing Widget using the JavaScript API, but it does not prevent invalid entries from submission into the database. The input text box on the attribute inspector will have a warning showing the attribute is not valid, but if the user submits the change, it still goes through.

I believe I need to use dijit.form.form widget to ensure invalid attributes are not submitted, but I am not quite sure how to implement this.

Any examples out there?

Thanks.
0 Kudos
1 Solution

Accepted Solutions
HemingZhu
Frequent Contributor
Hi,

I have implemented the validation text box for the editing Widget using the JavaScript API, but it does not prevent invalid entries from submission into the database. The input text box on the attribute inspector will have a warning showing the attribute is not valid, but if the user submits the change, it still goes through.

I believe I need to use dijit.form.form widget to ensure invalid attributes are not submitted, but I am not quite sure how to implement this.

Any examples out there?

Thanks.


First of all, if you set wrong type of data for an attribute field for example put a text string info a field with double type, the field will not accept a value. Secondly, if your specified a domain and/or subtypes for the attribute field, the field will not accept a value that is not in that domain or subtypes. In both cases the field value will not updated. Thirdly, you could further constrict the entries by code logice using validation like in your case. Something like the following:

dojo.connect(attInspector, "onAttributeChange", function(feature, fieldName, newFieldValue) {
            // specify thefieldName you want to further validate
            if (fieldName ==thefieldName)
            {
                var regularExpression = /^\d+(\.\d+)?$/;  //for example a positive value
                if ( newFieldValue.match(regularExpression))
                {
                     feature.attributes[fieldName] = newFieldValue;
                     feature.getLayer().applyEdits(null, [feature], null);
                 }
                else
                {
                     //alert("invalid entries for field " +fieldName);
                     return;
                }
             else
             {
                 feature.attributes[fieldName] = newFieldValue;
                 feature.getLayer().applyEdits(null, [feature], null);
              }
              ...
          });

View solution in original post

0 Kudos
2 Replies
HemingZhu
Frequent Contributor
Hi,

I have implemented the validation text box for the editing Widget using the JavaScript API, but it does not prevent invalid entries from submission into the database. The input text box on the attribute inspector will have a warning showing the attribute is not valid, but if the user submits the change, it still goes through.

I believe I need to use dijit.form.form widget to ensure invalid attributes are not submitted, but I am not quite sure how to implement this.

Any examples out there?

Thanks.


First of all, if you set wrong type of data for an attribute field for example put a text string info a field with double type, the field will not accept a value. Secondly, if your specified a domain and/or subtypes for the attribute field, the field will not accept a value that is not in that domain or subtypes. In both cases the field value will not updated. Thirdly, you could further constrict the entries by code logice using validation like in your case. Something like the following:

dojo.connect(attInspector, "onAttributeChange", function(feature, fieldName, newFieldValue) {
            // specify thefieldName you want to further validate
            if (fieldName ==thefieldName)
            {
                var regularExpression = /^\d+(\.\d+)?$/;  //for example a positive value
                if ( newFieldValue.match(regularExpression))
                {
                     feature.attributes[fieldName] = newFieldValue;
                     feature.getLayer().applyEdits(null, [feature], null);
                 }
                else
                {
                     //alert("invalid entries for field " +fieldName);
                     return;
                }
             else
             {
                 feature.attributes[fieldName] = newFieldValue;
                 feature.getLayer().applyEdits(null, [feature], null);
              }
              ...
          });
0 Kudos
JosephSaltenberger
Deactivated User
Thanks,

Your third point is the answer I was hoping for... the "onAttributeChange" event is what I was looking for.
0 Kudos