-
Notifications
You must be signed in to change notification settings - Fork 3
7. finishing up custom converter
lets add some field validation to this..
the form section above adds the onInput() event handler to each of the new fields.. we just need to call some function on the fields data as it changes
well, we HAVE the MM-Config.extension.js that is being loaded already, so we can put the functions in there.
one for each data type. and we can use the javascript regular expression function to validate the data 1 char at a time, live. That looks like this (without the regex strings, which are long.. look at the code if u need to)
// this is for the cron type field, I added to compliments Oct 24
function cron_validator(content){
return (cron_regex.exec(content) !== null)
}
// this is for the date field.. make sure its this year or later or it wont trigger
function date_validator(content){
let result=(new RegExp(date_regex).test(content)) // test that the field content matches the YYYY-MM-DD format
if(result){ // if true
if(!content.includes('.')){ // check if the content DOES SPECIFY an actual year 2021 or 2024 for example
result = new Date(content) >=new Date()
}
}
return result
}
and we have a css entry to turn the field red if the regex validation test fails..
.m_compliments .fieldError::before {
content: ' * incorrect format';
color: red;
display: block;
}
.. food for thought.. these fields require the user to type the text of the field format. there ARE visual date, and date/time pickers for the date one, we need to know if the date is specific to THIS year (2024-07-25), or the month/day in any year (birthday ....-07-25) for the cron.. once we have the date/time range, we need to convert that to the format required by cron.
the two fields could be extended with onClick handlers to trigger the pickers..