Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Skip field validation in ValuesManager

    I have a VLayout with multiple DynamicForm instances, all linked to the same ValuesManager (I use this technique to be able to create legends around fields).

    When I submit the value manager it's blocked because of a required field (in the data source) that I am not showing in the form (on purpose). Is there a way of skipping unshown fields? If I include the field as hidden in one of the forms and overwrite the "required" property with false, it works, but I would rather not want to do this.

    The thing is that I have other forms in my application without a ValuesManager where I don't include required fields and that works.

    #2
    This is an example to illustrate my point. I have a (server-side) generated data source. For simplicity I show only the essential parts (at least that's what I intend to do).

    Code:
        isc.RestDataSource.create({
            dataURL: 'addresses',
            fields: [
                { name: 'id', hidden: true, primaryKey: true, type: 'integer'},
                { name: 'customer_id', type: 'integer', required': true, canEdit: true },
                { name: 'street', type: 'text', required: true, canEdit: true }
            ],
            ID: 'addresses'
        });
    When I create just a form that uses this data source, but only one field (street), submitting works (I didn't include the submit button in the example, but in my application it's an "external" button that explicitly calls form.submit();

    Code:
        // submitting works
        isc.DynamicForm.create({
            dataSource: 'addresses',
            fields: [
                { name: 'street' }
            ],
            saveOnEnter: true
        });
    When I create a VLayout (I do this when I want multiple form blocks with a border around them, thus having isGroup set to true), submitting fails.

    Code:
        // submitting doesn't work
        isc.VLayout.create({
            initWidget: function () {
                var valuesManager = isc.ValuesManager.create({
                    dataSource: 'addresses'
                });
    
                this.members = [
                    isc.DynamicForm.create({
                        fields: [
                            { name: 'street' }
                        ],
                        saveOnEnter: true,
                        valuesManager: valuesManager
                    })
                ];
    
                this.Super('initWidget', arguments);
            }
        });
    Hopefully there's not a real typo in here, since this is an edited, simplified display of my application, just to show the goal I try to achieve.

    The thing is that in example one, submitting works, but in example two it doesn't (it complains that customer_id is required, but this is only visible via isc.showConsole()).

    Comment


      #3
      Please check out handleHiddenValidationErrors:
      http://www.smartclient.com/docs/10.0/a/b/c/go.html#method..ValuesManager.handleHiddenValidationErrors

      Comment


        #4
        Hi Dencel,

        I did that and AFAIK it only controls whether these hidden errors show up in the console or not. I did implement that method, returning false and indeed no logging occured, but also no submittal of the form.

        Comment


          #5
          It looks like I found the cause of the problem:

          The validate() method in DynamicForm has this piece of code:

          Code:
          dsFields = (validateHiddenFields && !ignoreDSFields && this.dataSource) ?
            isc.addProperties({}, this.getDataSource().getFields()) : null
          The validate() method in ValuesManager has this piece of code:

          Code:
          dsFields = this.dataSource ?
            isc.addProperties({}, this.getDataSource().getFields()) : null
          Thus if the ValuesManager is given a data source (it there another option?), it uses all its fields, without the option to ignore hidden fields. By the way, looking at the code for DynamicForm, I wonder if it's correct that when validateHiddenFields is true and ignoreDSFields is false, then all fields from the DataSource are used, but that's a "side question".

          Comment

          Working...
          X