Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Wht is the meaning of this syntax?

Avatar

Level 8

Hello

My requirement is that, i have to find out that the given(in question) variable / text field object has any value / contaning any value / holding any value / does user has inputted any value?

I mean, if tehre is any blank white spaces, null......then, am not interested, it should hold REALLY a value.

So, when i searched in google, i found the below,

var myTestField

if (!/^\s*$/.test(myTestField))

// yes, some value (not blank, not null) is there, you can put ur logic here

{

1) Pls. let me know is it gonna work for my requirement (as our system is down, i can not test it!)?

2) is there any better approach? i guess, we have hasValue in FormCalc.

Thank you

7 Replies

Avatar

Level 10

You can use FormCalc syntax as below.. This will exclude any spaces in the field value.

if(hasValue(TextField1)) then

//Do your processing

endif

If you want to use Java Script, then trim the field for any spaces and then check for the value..

Thanks

Srini

Avatar

Level 8

Thank you.

So, would you like to say that, my approach is NOT a safe/recommended/good approach, as below?

var myTestField

if (!/^\s*$/.test(myTestField))

// yes, some value (not blank, not null) is there, you can put ur logic here

{

1) If its safe/good then i want to go with my approach.

2) If its not safe/good...... currently i put some other stuff (code) for this myTestField in JavaScript.....so, now, can i implement your suggestion of FormCalc, meaning, can i implement mixture of JavaScript & FormCalc fo rthe same myTestField?

Thank you

Avatar

Level 10

It is not aboout safe.. Your requirement is to check whether a field has value or not. And your code should not consider any spaces in the field as value.

You can write code in FromCalc OR JavaScript to achieve the above..

The above FormCalc condition will be true when a value is entered in the field other than space. So you can write processing statements inside that if block.

You can write a similar code in Java Script to do the same.

var myTestField = YourFormField.rawValue;

//Trim the field value to remove spaces
if(myTestField.replace(/^\s+|\s+$/g,"") == ""){
  //Write your code if field is empty.

}

There is no Trim function in Java script you have to write code to trim the field.

Thanks

Srini

Avatar

Level 8

Thank you.

I got this info (code snippet) from the below link (pls. see the 1st answer from CMS)

http://stackoverflow.com/questions/2588229/how-to-check-if-form-input-has-value

Thank you

Avatar

Level 8

Hello

Did u get a chance, to see the mentioned link?

Thank you    

Avatar

Level 10

I saw the link.. Did you try the solution provided?

Do you still have issues?

Avatar

Level 8

No, i didn't tried, bcz still our system is down!! Hmmmmm.

Thank you