Has anyone implemented a custom fieldtype that forces a user to input a value between a specified range (e.g. 10000 - 12000) or is there a way of using an existing Contour field type to accomplish this?
You'll need to create a new one for this, it should be pretty simply, add 2 props to the custom fieldtype (like rangestart, rangestop) and then override the validate method where you check if the submitted value is between that range
I have just remembered that I have client side validation enabled for the forms, and the solution obviously only validates server side when the Next button has been clicked on the page. What would be involved to add client side validation to a custom field type, do you have any examples?
Since we use jquery validate you should be able to just use that, so if jquery validates unobtrisive supports it out of the box you'll just need to add the attributes to your input on your view
If it doesn't supports it out of the box you can write an extender for jquery validate
Numerical Range Custom Fieldtype
Has anyone implemented a custom fieldtype that forces a user to input a value between a specified range (e.g. 10000 - 12000) or is there a way of using an existing Contour field type to accomplish this?
Hi Graham,
You'll need to create a new one for this, it should be pretty simply, add 2 props to the custom fieldtype (like rangestart, rangestop) and then override the validate method where you check if the submitted value is between that range
Should be something like
//check range here and return a list of expections
Full validate method could look like
//check range here and return a list of expections
Thanks for the in-depth information Tim, I shall give it a go :)
Great, let me know if that does the trick :)
Hi Tim,
I have just remembered that I have client side validation enabled for the forms, and the solution obviously only validates server side when the Next button has been clicked on the page. What would be involved to add client side validation to a custom field type, do you have any examples?
Thanks.
Since we use jquery validate you should be able to just use that, so if jquery validates unobtrisive supports it out of the box you'll just need to add the attributes to your input on your view
If it doesn't supports it out of the box you can write an extender for jquery validate
Think you'll need to add
data-val-range
=
"The field Age must be between 1 and 130."
data-val-range-max
=
"130"
data-val-range-min
=
"1"
Thanks Tim, sounds interesting, I haven't delved into jquery validator before so I will have a read up on it and have a go with what you posted above
You can fetch the additional settings in the fieldtype view with Model.AdditionalSettings["key"]
Thanks Tim, worked a treat
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.