ember-bootstrap icon indicating copy to clipboard operation
ember-bootstrap copied to clipboard

Add a method for reseting a form's child element validations for form reuse

Open dspigarelli opened this issue 8 years ago • 8 comments

I have a bs-form embedded in a bs-modal. If any of the form's child elements have been focused on during a previous iteration of the modal, the child element retains the showOwnValidation=true and immediately display their validation when the modal is opened. The request is some way to reset the showOwnValidation back to false between iterations of the modal.

Work around for now is to surround the bs-modal or embedded bs-form with an {{#if...}} conditioned on the modal's display.

Example:

{{#if showModal}}
  {{#bs-modal open=showModal ...}}
    {{#bs-form}}
    ...
    {{/bs-form}}
  {{/bs-modal}}
{{/if}}

Output from ember bootstrap:info (available since 1.0.0-alpha.9):

 $ ember bootstrap:info
Npm packages:
ember-bootstrap: 1.0.0-alpha.12 -> 1.0.0-alpha.12
ember-cli: 2.13.2 -> 2.13.2
bootstrap: n/a
bootstrap-sass: ^3.3.7 -> 3.3.7
ember-cli-sass: 6.1.3 -> 6.1.3
ember-cli-less: n/a
Bower packages:
bootstrap: n/a
bootstrap-sass: n/a
ember-bootstrap configuration:
importBootstrapCSS: false

dspigarelli avatar May 25 '17 19:05 dspigarelli

@simonihmig how can I help push this forward?

RobbieTheWagner avatar Oct 14 '20 21:10 RobbieTheWagner

@rwwagner90 Great to see that you are willing to work on this one. I think discussing public API would be the first step.

The title of this issue assumes that it should be done per form element. But the use case requires per form. We should get an agreement of what to support.

Some of the components provided by ember bootstrap use an argument to reset internal state. Setting the property bound to it, resets the internal state. E.g. <BsButton> has a @reset argument, which resets the fulfilled / rejected state.

To be honest I'm not a big fan of that pattern. But I'm also not aware of an alternative pattern. And consistency of the APIs is also an important point.

For this specific case I'm wondering if it should be integrated with @model argument. Maybe validation state should be reset when object used as model changes? 🤔

jelhan avatar Oct 15 '20 12:10 jelhan

@jelhan

For this specific case I'm wondering if it should be integrated with @model argument. Maybe validation state should be reset when object used as model changes?

This sounds reasonable. I think the model for our forms changes each time. The problem is the form elements themselves do not always change, so if one form has the same field as another and we switch forms, we end up with stale validation state.

RobbieTheWagner avatar Oct 15 '20 14:10 RobbieTheWagner

@jelhan

For this specific case I'm wondering if it should be integrated with @model argument. Maybe validation state should be reset when object used as model changes?

This sounds reasonable. I think the model for our forms changes each time. The problem is the form elements themselves do not always change, so if one form has the same field as another and we switch forms, we end up with stale validation state.

Not sure if I can follow. I wasn't describing a feature existing today but a potential public API to serve the use case.

To be more precise I think we would need to add an additional argument @resetValidationStateOnModelChange to <BsForm>. If true the validation state of all form elements of the form should be reset when the object bound to @model argument changes.

@resetValidationStateOnModelChange needs to be false by default for backward compatibility. We might want to change default value in next major release.

jelhan avatar Oct 15 '20 17:10 jelhan

@jelhan

Not sure if I can follow. I wasn't describing a feature existing today but a potential public API to serve the use case.

Yes, I did not say it existed, I said it sounds reasonable and I agree.

I think @resetValidationStateOnModelChange sounds like a good API. Shouldn't it be true always though? If the whole model changes, I am not sure why we would want to keep old validations around.

RobbieTheWagner avatar Oct 19 '20 16:10 RobbieTheWagner

I think @resetValidationStateOnModelChange sounds like a good API. Shouldn't it be true always though? If the whole model changes, I am not sure why we would want to keep old validations around.

We can't introduce breaking changes. Therefore it must be false at least until the next major.

jelhan avatar Oct 19 '20 20:10 jelhan

@dspigarelli @rstudner perhaps this is something someone in Expel could take on internally? Could be a good way to contribute back 😃

RobbieTheWagner avatar Jan 22 '21 16:01 RobbieTheWagner

Is this still an issue in recent versions? I would expect that <BsModal> and a <BsForm> components are teardown when the modal is hidden. But I could be wrong. At least I cannot recall having noticed this bug.

jelhan avatar Nov 06 '23 17:11 jelhan