Skip navigation
Currently Being Moderated

validating for empty text field

Mar 30, 2009 10:52 AM

Hi All !

I want to conditionally validate the presence of a text field based on a radio button i.e. it is a yes/no radio button, and if "yes" is clicked, then a text field has to have a value. To do so, I wrote the following script in the Script Editor for the text_field and chose the "validate" option of the "Show" dropdown :

(radio_field.rawValue == "1") || (radio_field.rawValue == "2" && !text_field.isNull && text_field.rawValue.length > 1)

It does not work for the case where "yes" is clicked and text_field is empty. In that case, there is no error message. How can I validate that text_field is not empty when "yes" is clicked ?


  • Currently Being Moderated
    Mar 30, 2009 11:09 AM   in reply to (Martin_Leboeuf)
    Do it the other way around .....on the change event of the radio button group:

    if ((this.rawValue == "Yes") && (textField.rawValue == null)){
    app.alert("TextField cannot be empty with this option")
    Mark as:
  • Currently Being Moderated
    Mar 31, 2009 5:50 AM   in reply to (Martin_Leboeuf)

    I am not completly sure to have understood you right.
    Some questions for better understanding.

    1) Do you want to validate the textfield WHEN you click the button (that means if it is empty a message appears when you click)
    2) Do you want a user to be able to change the textfield entry but not erase it?
    3) Do you want to make a validation before sending the mail? So the field simply gets obligatory but has not to be filled out the moment the user clicks.

    4) Did Paul's solution work somehow? Or could there additionally be a value/naming problem? (Just to make sure)

    I think the main reason you are not satisfied is, because you only put the script into the change field of the RB.

    I'd add a similar script into the exit field of the Textfield like:

    if ((this.rawValue != null) && (radiobutton.rawValue == "Yes"))
    app.alert("TextField cannot be empty with your radiobutton choice")

    Then you can't delte the fieldvalue anymore without replacing something.

    Though I am not sure, if it's possible to send the data "wrongly" though...
    Mark as:
  • Currently Being Moderated
    Mar 31, 2009 7:24 AM   in reply to (Martin_Leboeuf)
    Acrobat/Reader will run validations automatically for you and not allow you to submit unless these validatiion conditions are met. In your case the field starts off as open and based on a condition you would make it mandatory. So we merely have to make the field mandatory (under the right conditions) and allow the submit logic inherent in the client to work. So on the change event of the checkbox you can do something like this:

    if (this.rawValue == 1){
    TextField1.validate.nullTest = "error"
    } else {
    TextField1.validate.nullTest = ""

    Then when the user tries to submit an error message will appear indicating that they must fill out the empty field before they can submit.
    Mark as:
  • Currently Being Moderated
    Mar 31, 2009 7:28 AM   in reply to (Martin_Leboeuf)
    Hihi thought so :)

    That was why I asked. ^^
    It was my first question in here too... though I have to say, I think my scripts have gotten better since that time ;D

    One solution:

    Should normally work in your case too :)
    Mark as:
  • Currently Being Moderated
    Mar 31, 2009 7:52 AM   in reply to (Martin_Leboeuf)
    ah yeah...
    Forgot to tell:
    I also added in the other button (same event):

    if (this.rawValue == "N")
    {TextField1.validate.nullTest = "disabled";
    TextField1.border.edge.color.value = "255,255,255";
    Textfield1.assist.toolTip.value = "This field is optional...";

    Just to ensure it won't stay obligatory when the user simply changes his mind about the button ;D
    If you don't want the colors, just delte the color field ^^

    Hope these helped :)
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)