Alphanumeric questions, by default, can be left blank. What is the simplest way to change that behaviour, i.e. make them compulsory?
Thanks for your help.
Make alphanumeric questions compulsory
Re: Make alphanumeric questions compulsory
There is no setting to do this, you will have to add logic to ensure the string isn't empty.
or
Sherrell
Code: Select all
if strip(myString) <> "" then // the string isn't blank
// continue with processing the string
endif;
Code: Select all
if length(strip(myString)) > 0 then // the string length isn't zero
// continue with processing the string
endif;
Re: Make alphanumeric questions compulsory
Thank you very much, Sherrell.
Wouldn't it be nice to have this as a feature, e.g. a property of the question, with a default that can be set to either compulsory or not?
Wouldn't it be nice to have this as a feature, e.g. a property of the question, with a default that can be set to either compulsory or not?
Re: Make alphanumeric questions compulsory
I have a similar issue.
I have several Alhpanumeric fields that I want want to make inputs compulsory. I am new to coding so I just copied the codes above and pasted in one of the fields logic section. I did replace "mystring" with Structure_Code ( Name of the variable) and compiled. But the field still accepts zeo inputs.
Any help please? Maybe I did something wrong.
I have several Alhpanumeric fields that I want want to make inputs compulsory. I am new to coding so I just copied the codes above and pasted in one of the fields logic section. I did replace "mystring" with Structure_Code ( Name of the variable) and compiled. But the field still accepts zeo inputs.
Any help please? Maybe I did something wrong.
Re: Make alphanumeric questions compulsory
The logic needs to be in the postproc of the variable you are testing. Alternatively, you could make this a function and call the function for all string variables so you don't have to repeat the logic. If your code isn't working, please paste the entire code block (starting from PROC VarName).
As for making this a CSPro setting, I agree this could be useful--tho how would that work? If we say don't allow blank, then invariably we'd want to stipulate the string length (for example, having a person's name field be 1 character probably doesn't make sense). You would then likely want to stipulate whether only alphabetic characters could be entered, or a mix of alphabetic & numeric characters, etc. Any thoughts?
Thanks,
Sherrell
As for making this a CSPro setting, I agree this could be useful--tho how would that work? If we say don't allow blank, then invariably we'd want to stipulate the string length (for example, having a person's name field be 1 character probably doesn't make sense). You would then likely want to stipulate whether only alphabetic characters could be entered, or a mix of alphabetic & numeric characters, etc. Any thoughts?
Thanks,
Sherrell
-
- Posts: 20
- Joined: August 17th, 2022, 11:07 pm
Re: Make alphanumeric questions compulsory
Hi JeffCid,JeffCid wrote: ↑September 13th, 2022, 2:49 am I have a similar issue.
I have several Alhpanumeric fields that I want want to make inputs compulsory. I am new to coding so I just copied the codes above and pasted in one of the fields logic section. I did replace "mystring" with Structure_Code ( Name of the variable) and compiled. But the field still accepts zeo inputs.
Any help please? Maybe I did something wrong.
I use this code for my alphanumeric fields.
Code: Select all
if strip($) = "" then // if the string is blank
errmsg("You can't leave this question blank");
reenter;
elseif $ = "None" then // if the respondent answered None or Refused
//continue...
endif;
Re: Make alphanumeric questions compulsory
Thanks a lot ! This code is working. One quick one
How do I run this code once on a number of fields at once?
How do I run this code once on a number of fields at once?
-
- Posts: 1801
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Make alphanumeric questions compulsory
You can write a function and then call it in every location where you want to made this check. For example:
function EnsureNotBlank(string value, numeric min_length = 1)
if length(strip(value)) < min_length then
errmsg("You must enter text of length %d+ for field %s", min_length, getsymbol());
reenter;
endif;
end;
PROC AAA
EnsureNotBlank($);
PROC BBB
EnsureNotBlank($, 5);
if length(strip(value)) < min_length then
errmsg("You must enter text of length %d+ for field %s", min_length, getsymbol());
reenter;
endif;
end;
PROC AAA
EnsureNotBlank($);
PROC BBB
EnsureNotBlank($, 5);
Re: Make alphanumeric questions compulsory
Sure, thanks!