Additional Data Fields validation
-
Is there a way to validate that input in Additional Data Fields are in format with set constraints? – Etc. a date input as m/d/y
-
Hi, it can be done with Javascript hooks. Do you have knowledge of Javascript?
Regards
Nickolas
Hi Nikolas
I have a very limited knowledge of javascript, but I do have programming experience. So if you point me in the right direction maybe I can solve it on my own
Thanks!
Okay I got it fixed with some javascript and simple RedExp.
Hi, here is sample Javascript code that you need to put below the shortcode:
<script type="text/javascript> if(window.addEventListener) { window.addEventListener("load", wfu_check_userdata, false); } else if(window.attachEvent) { window.attachEvent("onload", wfu_check_userdata); } else { window["onload"] = wfu_check_userdata; } function wfu_check_userdata() { Code_Initializators[Code_Initializators.length] = function(sid) { var Custom_Code_Objects = {}; Custom_Code_Objects.pre_start_check = function (attr) { if (!attr) return attr; var sid = this.sid; var fid = 1; var WFU = GlobalData.WFU[sid]; var props = WFU.userdata.props[fid]; var result = true; //get and check field value var value = WFU.userdata.getValue(props); return result; } return Custom_Code_Objects; } wfu_Load_Code_Connectors(1); } </script>
This code inserts a check before the upload starts. If the check passes, then function Custom_Code_Objects.pre_start_check should return true, otherwise it should return false.
In this line
var value = WFU.userdata.getValue(props);
I show you how you can get the value of the field with index fid.Regards
Nickolas
- This reply was modified 4 years, 11 months ago by nickboss.
Hi Nickolas
Looks great and a lot more thought through than what I hacked out ??
But I’m having some difficulties understanding where I can setup the parameters for the validation. Do I need to set the props value ?
I have this RedExp that I want it to correspond to:
/^\d{1,3}.\d{1,20},\d{1,3}.\d{1,20}/Thanks for all you help !
And just saw that without any changes to the code you just send, it gives:
TypeError: props is undefinedHi, strange, can I see the page myself? what is the URL?
Nickolas
Hi
Sure the url is:
https://wi-form.com/uploader/
and the pwd isNickolas
The uploader only takes .obj
And I made a script that alerts if the user input doesn’t match
"/^\d{1,3}.\d{1,20},\d{1,3}.\d{1,20}/"
formatting, but as of right now the user can still upload even though the input doesn’t match.My script is:
" var input = document.getElementsByClassName("file_userdata_message") var userinput = document.getElementById("hiddeninput_1_userdata_0") input[0].addEventListener("blur", function() { userinputNow = userinput.value regExp = /^\d{1,3}.\d{1,20},\d{1,3}.\d{1,20}/; var match = regExp.test(userinputNow); if (match){ return } else if (userinputNow == 0){ return } else{ alert('Please enter valid coordinates') } }); "
- This reply was modified 4 years, 11 months ago by Jan Dembowski. Reason: Formatting
Hi Nikolas
Okay got it fixed ??
Turned out that it was just because the fid was set to 1 and the userinput element was 0
From there I just implemented the RedExp and if it was not a match, it alerts (could be done more elegant, but it works) and returns false. Thanks for all the help !
For anyone in the future here is the working script:
if(window.addEventListener) { window.addEventListener(“load”, wfu_check_userdata, false); }
else if(window.attachEvent) { window.attachEvent(“onload”, wfu_check_userdata); }
else { window[“onload”] = wfu_check_userdata; }function wfu_check_userdata() {
Code_Initializators[Code_Initializators.length] = function(sid) {
var Custom_Code_Objects = {};
Custom_Code_Objects.pre_start_check = function (attr) {
if (!attr) return attr;
regExp = /^\d{1,3}.\d{1,20},\d{1,3}.\d{1,20}/;
var sid = this.sid;
var fid = 0;
var WFU = GlobalData.WFU[sid];
var props = WFU.userdata.props[fid];
var result = true;
//get and check field value
var value = WFU.userdata.getValue(props);
var match = regExp.test(value)
console.log(value)
if (match) {
return result;
}
else {
alert(‘Please enter valid coordinates’)
return false;}
}
return Custom_Code_Objects;
}
wfu_Load_Code_Connectors(1);
}Ok good.
Regards
Nickolas
- The topic ‘Additional Data Fields validation’ is closed to new replies.