PreferencesFX
PreferencesFX copied to clipboard
Required Fields Enhancement
In FormsFX there is the ability to add required fields. We can currently use validators, but it would be nice to be able to mark a field as required. When exiting the window where a save would be called, validate the whole form and prevent closing if any required fields are not filled in.
As a side effect, having a non-required field that is invalid would have to be carefully scruitinized, because say you have a validator for e-mail address on a non-required field. It is considered invalid if the value is blank (as far as I can see currently) so those fields would be skipped unless they have a non-zero length value that is invalid (i.e. someone@somewhere. would be considered invalid)
This presents a nice addition in my opinion, feel free to create a PR that implements this!
Regarding your point about the invalidity, that's a good point. I think it depends on what the intention is. I can think of cases where for example you could specify an email address to send automatic reports to, or if the field is not filled, it wouldn't do that. In this case it would make sense to not have a required field, but still ensure that if the user enters an email that it is valid. Of course, I can also imagine cases for when both is required.
Agreed. It would implement the validators that are currently there to handle whether the value is valid or not (a possible addition would need to be not allowing close/save with an invalid value in there, or at least an alert before the value gets wiped out.
The second would be to add a required property to the fields themselves, and then when closing the window check to make sure that required fields are entered. IF they choose to exit anyway the setting would be defaulted back to its initial value.
I'll work on this a bit and see what I can come up with.