Help with ternary statement

<input type="hidden" id="inp_user_type_status" name="user_type_status" dmx-bind:value="((chklist_personal_data.data.query.user_type != null) &&(chklist_personal_data.data.query.user_type_override != 1)) ? 1 : 0">

The above is simply to assign a value based on the below logic.
if usertype is not null and usertype_override is not 1 then 1 else 0
It always returns 0 even if the criteria is met.

Am I doing something wrong?

I might be wrong but it looks like you have user_type is not null in your statement?

Sorry i should have said is not null, I really want to say if a value exists in the field

You could use the .length() formatter to check whether a value exists. It would also account for an empty string whereas null has to be null (not empty)

So you need to just check:

dmx-bind:value="(chklist_personal_data.data.query.user_type && chklist_personal_data.data.query.user_type_override != 1) ? 1 : 0"

which means if user_type has a value and user_type_override is not equal to 1, then the value would be 1, otherwise it will be 0.

I have tried this and still get 0 as the result, but I will try again

If you get 0 then some of the 2 conditions is not met :slight_smile:

I know but they have, when I check the DB…been on this for 2 hours…should have been a 1 minute thing.

Perhaps you are comparing a string value to the number one?

Maybe just add:

<p>{{chklist_personal_data.data.query.user_type}}</p>
<p>{{chklist_personal_data.data.query.user_type_override}}</p>

somewhere on the page and see what they output :slight_smile:

tried that as well they are stored as strings and had all the values compared strings before previously as well.

I’ve been checking the values in the browsers inspector and they are as expected, I also just tried what you suggested and it printed the value for user_type, the user_type_override is stored as null

(chklist_personal_data.data.query.user_type_override != 1) ? 1 : 0
works as expected while

(chklist_personal_data.data.query.user_type) ? 1 : 0
this does not - checking that the value exists always fails. have confirmed that the field names are correct and that the value in this case ‘applicant’ is in the db.

(chklist_personal_data.data.query.user_type == null) ? 1 : 0
The above just came back as true, which doesn’t make sense.

The image shows the source of the values from the browser, yet the above statement is coming back as true. I hope this is something really silly I’m looking past.

checking for the length does seem to be working, thanks bpj. I’m not sure what is wrong but this is getting around the issue.

Is there any chance that there is a bug causing this, I’ve checked multiple times and this still isn’t behaving as expected

I checked that and expression like your works fine when the query returns results.
What server model are you using?

Using PHP and Mysql on a mac

Since the length formatter is working I think it is actually an empty string and not a null value. The length formatter is only for strings, you get an error in the console when it used on a null value.