Best Practises for forms with field relations

Hi all,

currently I’m facing the challange of relationships between input-fields in one form and would like to ask you if you have any clever ideas for me to solve that.

My Problem:
I have to input fields:

<input value.bind="mymodel.attribute1" />
<input value.bind="mymodel.attribute2" if.bind="!mymodel.attribute1" />

Now, in case the user first fills the attribute2 and after that attribute1, the second attribute input field disappears as expected, but the information is still stored and send via POST.
Does aurelia have any cool feature to prevent the sending of “hidden” input fields?

In my current project I have also dependencies from child-model to parent model which is quite hard and ugly to validate :’(

1 Like

Personally, I think tying the functionality to the UI state is asking for trouble. That said, the vanilla behavior where data from disabled inputs are not sent sets a precedent here. The solution here depends on the intended functionality: If the user clears the first input should the second reappear with any previous state intact?

Yes? I would create a method which maps the model to what should be expected by the API. This approach allows you to keep the UI side model intact for subsequent visits (such as when an error needs corrected).

No? For this I would update dependent properties in the setter of the parent properties.

2 Likes