October: Validate backend forms client-side breaks current backend forms

Created on 18 May 2020  路  6Comments  路  Source: octobercms/october

I upgraded to the latest version and this pr broke my current forms in the backend: #4804.

I have a backend form field with a dependsOn on another form field. The depends on form field only gets updated when all the required fields are filled in, but not all required fields are filled in when you are in the middle of creating a new record.

For example my fields.yaml:

    name:
        label: oms.core::lang.shop.name
        required: true
        type: text 
        span: auto

    code:
        label: oms.core::lang.shop.shop_code
        type: dropdown
        span: auto
        emptyOption: oms.core::lang.shop.select_shop_code

    _shop_fields:
        type: partial
        dependsOn: code

When I change the dropdown without filling in the name field, the _shop_fields isn't updating and the html 5 required field validation pops up. You can also see that the _shop_fields loading spinner is stuck, because the request isn't executed because of this pr.

image

Completed Bug

All 6 comments

@jacobdekeizer I'm not sure this is a bug to be honest, shouldn't it be preventing the request from being submitted until you have fulfilled the requirement? If the field doesn't actually have to be required in all cases, then you should be removing that rule when it's not applicable or only adding it when it is.

@bennothommo any thoughts on this?

@LukeTowers I'm leaning towards it being a bug - I don't think validation should stop a dependent field being updated if another field is required, especially if that required field has nothing to do with the dependency, as @jacobdekeizer's demo code implies.

I'm also thinking of the scenario where say there's 20 other fields underneath the fields that @jacobdekeizer has above, and one of the later fields just happens to be required as well - if someone is filling out the form more or less from top to bottom, this later field would probably stop the dependency update as well.

Ideally, the client-side validation should only trigger when a field with validation rules on itself is changed, and at the end of the form when the user does their final submission.

@LukeTowers This is a frustrating bug for the end user. Like @bennothommo said, if there are 20 other fields where some of them are required to post the form, you have to fill in all the required fields before the dependsOn fields work and are updated. This is wrong and different from the behaviour before this pr got merged. Could you guys revert that pr until it's fixed or make a fix for it?

@bennothommo is there a way that we can ignore the client side validation on any requests triggered by the dependency logic? Perhaps by adding a flag or option to the $.request method to bypass that check, and then add that flag to request triggered by the dependent logic?

@LukeTowers I was suprised the client-side validation was triggering at all with AJAX requests - I was under the impression it's supposed to only trigger when a form is submitted. I'll have a look into it.

Was this page helpful?
0 / 5 - 0 ratings