Change null value on entry field

I have a text block that updates based on the value of an entry field using onSelectChange. If you start entering data but then delete it all, the value becomes "null" and the text block displays "~~~null~~~". I'm trying to figure out how to prevent the "null" value from appearing in the text block when you delete text previously entered.

I tried a Modify Variable with the condition "contains null" before the action to change contents and as a condition of the change contents action to no avail. So the order of operations was either:

onSelectChange: Set variable value empty IF variable contains "null"

onSelectChange: Change contents to variable


onSelectChange: Change contents IF variable does not contain "null"

I also tried the condition "not empty" on the change contents with the first set of actions, but this displayed the character you enter first. None worked, even with a delay on the Change Contents action. Suggestions are quite welcome. I can try and post a quick sample later if needed.

Discussion (8)

That comes close, but still doesn't work quite right.

OnSelectChange: Set variable1 empty IF variable1 is empty

OnSelectChange: Set text box variable1 if variable1 is NOT empty

What happens here is that if I enter data in the entry field, then delete using backspace, it retains the first character I typed. It's as if it's not seeing that last backspace keystroke.

Here's an attachment with an editable entry field and both a read-only entry field and text block that get updated on SelectChange of the editable field.

It works if you have specific text or value you want to change it to, but not if you want to set it so that nothing displays. A workaround, I think, might be to just add a space to the "new value", making the entry field effectively blank.

Take "Jason" out of that field and you get that null text again.

A null variable doesn't contain the string "null"; in Lectora, a null variable is empty. Set your condition to

Set variable value empty IF variable Is Empty


Change contents IF variable Is Not Empty

(In most programming languages, a null variable is not empty either; it's nothing, and must be tested for with "Is Null" or "Is Not Null". However, in Lectora, null variables are treated as empty.)

is Empty works for this Jason.

Working example.

If you replace Jason with ' ' (no quotes) I think you'll get what you want.

Jason, did you try this?

Hi Darrel - I haven't yet. I got caught up in a simulation page that is really intense and triggers a ton of different branches, so have been focusing on that. I don't want to lose my place, but will be going back to it before I go to QA. Hope you're well!

Discussions have been disabled for this post