Hi All,
I remember that I promised to share my ideas and proof of concept about a Form Builder created with Fred (I just can’t remember who asked me to share this), but I am now reaching a phase on my project that I will have to start thinking about this.
I found a very interesting concept on Fred that can be used for this purpose: fred-bind:
First things first:
- The form concept:
I am starting now to implement the form in HTML and the idea is to use the Javascript ValidityState method in order to apply customized HTML5 validation model:
Possible Custom messages per validity events:
ValidityState = {
badInput: false,
customError: false,
patternMismatch: false,
rangeOverflow: false,
rangeUnderflow: false,
stepMismatch: false,
tooLong: false,
tooShort: false,
typeMismatch: false,
valid: false,
valueMissing: true
};
Support material:
https://www.w3.org/TR/html5/forms.html#the-constraint-validation-api
https://medium.com/the-ui-files/form-validation-with-javascript-4fcf4dd32846
https://developer.mozilla.org/en-US/docs/Web/API/ValidityState
Check patters:
http://html5pattern.com/Names
I am thinking about a dynamic Javascript function that will read some expected data-
attributes and use them as data feeder for custom errors and validation patterns.
The HTML of a simple text field shall look like this:
<div class="form-group form-label-group col-12 col-lg-6">
<input
type="text"
class="form-control form-control-lg"
id="InputIdNumber"
name="InputIdNumber"
placeholder="ID Card number"
aria-describedby="InputIdNumberHelp"
data-toggle="tooltip"
data-placement="top"
data-html="true"
title="Insert your complete ID Card Number.<br>Example: 11111111 1<span class='text-danger font-weight-bold'>*</span>"
pattern="[A-Z0-9 ]{1,14}"
minlength="7"
onChange="validateField('InputIdNumber')"
data-label="ID Card Number"
data-specialValitation = "2"
data-badInput="Format not recognized by the browser"
data-patternMismatch="The inserted ID Card number is not recognized as valid."
data-rangeOverflow=""
data-rangeUnderflow=""
data-stepMismatch=""
data-tooLong="You can only insert up to 14 caracters"
data-tooShort="Insert at least 7 characters"
data-typeMismatch="Please insert a valid ID Card number. Example: 11111111 1"
data-valueMissing="This field is mandatory!"
data-valid="OK"
required>
<label for="InputIdNumber" class="">ID Card Number</label>
<small id="InputIdNumberHelp" class="form-text"><span class="text-danger font-weight-bold">*</span> Mandatory Field</small>
<div class="invalid-tooltip" id="InputIdNumberErrMsg">
This is a mandatory field.
</div>
<div class="valid-tooltip" id="InputIdNumberSucMsg">
Valid ID Card.
</div>
</div>
- The Fred idea:
Create a Fred element with option set having regular configurations to be passed to FormIt parameters in order to build the snippet call.
Then, we can create a dropzone in order to allow to drag and drop the abive HTML code that would have this on the bottom of it:
<div class="modal">
<div class="modal-header">New Field Parameters:</div>
<div class="modal-content">
<div class="my-3 border">
<div>Tooltip helper text</div>
<div data-fred-name="fred-form-field-title" data-fred-bind="fred-form-field-title-attr">Insert your complete ID Card Number.<br>Example: 11111111 1<span class='text-danger font-weight-bold'>*</span></div>
</div>
<div class="my-3 border">
<div>Bad Input Error Message</div>
<div data-fred-name="fred-form-field-badInput" data-fred-bind="fred-form-field-badInput-attr">Format not recognized by the browser</div>
</div>
...
</div>
</div>
In order to activate this modal, We can add a div with data-fred-render="false"
that would call this modal, and then change a bit the HTML of the field to have this working:
<div class="form-group form-label-group col-12 col-lg-6">
<input
...
title="<span data-fred-name='fred-form-field-title-attr'></span>"
...
data-badInput="<span data-fred-name='fred-form-field-badInput-attr'></span>"
...
>
</div>
This way we would be able to allow user to customize the different field options, including field type, different parameters, etc.
Couple of things missing:
- I think I cannot have bindings to placeholders. This would make our life a lot easier;
-
minlenght
is just a number, so I am still thinking how I can handle this without using a span for the fred binding to work; - How can I handle select boxes options? I believe that there is nothing like migx for the frontent (there is
MIGXfe
, but it is not documented);
Please share your ideas, as this can also help Fred devs to optimize fred for these use cases as well.
Many thanks in advance all for your opinions and help.
Cheers