Is there a way to tell whether a placeholder hasn’t been set at all vs. whether it has been set with an empty value?
I have a web form that updates a database record.
I’m using FormIt to validate the form.
When the page loads the first time (with an existing database record), each field should be populated by the value from the database.
If the user edits and submits the form, but FormIt stops it & kicks it back due to validation errors, each field should be populated by the value that the user just tried to submit.
Here’s what I’ve come up with so far for achieving this:
<textarea name="hairstyle:required" id="hairstyle" class="inputclass">[[+fi.hairstyle:empty=`[[+hairstyle]]`]]</textarea> <span class="error">[[+fi.error.hairstyle]]</span>
What I want this placeholder syntax to mean is "if FormIt has captured a user-entered value for this field, use that... otherwise use the value stored in the database".
It works right on first load - [[+fi.hairstyle]] is empty, so it uses the [[+hairstyle]] value from the db instead.
However, if the user clears out this field (a required field), FormIt stops the submission and kicks out a "This field is required" message to [[+fi.error.hairstyle]]. But - since [[+fi.hairstyle]] is "empty", the value from the database is displayed in the field. What I really want in this case is the field to be empty, so that the user can see that they left the field empty & the error message they are seeing makes sense.
If there were a filter that triggered when the placeholder hasn’t been set at all (as opposed to when its set with an empty string), I think that would be the perfect solution here.
If it is possible to distinguish between "not set" and "empty", I’d like to propose a :notset filter be added to the core list of filters.
If it isn’t possible to distinguish... any suggestions for how to do this?