• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to set an app alert for a hidden field when its become visible

Participant ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

Hello All,
I am a complete novice with Java and have gotten as far as I have with copying script from various posts on the community.  I have a form for salesmen and I am adding individual alerts for any required fields which are not filled in.  Each field will have its own alert and not a generic one, (a lot of hand holding is required for them to fill out the forms correctly).  The script below is on a submit button and works fine until I get to the last else if statement.  At this statement I require the dropdown box to have a selection other than its default for the form to be submitted (as with the previous staements).  Once the first option (Named 'Stock') in the order-stock1 dropdown, has been selected 4 hidden fields appear.  I require the first field to be filled in (the other 3 are optional).  Likewise when the second option (Named 'Order') is selected the 'Stock' fields become hidden and 4 different fields become visible again the first of which is required and the other 3 are optional.  (Just to clarify if stock is selected, orders are hidden and visa versa) How can I adapt my code to make this work please?

 

if (this.getField("salesman").valueAsString==this.getField("salesman").defaultValue) {
app.alert("You must select a Sales Person.");

} else if (this.getField("dealdate").value=="") {
app.alert("You must select todays date.");

} else if (this.getField("customerdetails").valueAsString==this.getField("customerdetails").defaultValue) {
app.alert("You must select a customer type.");

} else if (this.getField("financeyn").valueAsString==this.getField("financeyn").defaultValue) {
app.alert("You must select if Finance is required.");

} else if (this.getField("date&send").valueAsString==this.getField("date&send").defaultValue) {
app.alert("You must select 'Yes' or 'No' on the immediate invoice dropdown.\n\nPlease check with *** or *** if selecting 'Yes' on a unit which is not in stock..");

} else if (this.getField("order-stock1").valueAsString==this.getField("order-stock1").defaultValue) {
app.alert("You must select if the unit is in stock or requires ordering.");
(this.getField("stock").display==display.visible) {
app.alert("You must enter at least one stock number.");

}

Any help would be greatly appreciated

TOPICS
Create PDFs , How to , JavaScript , PDF forms

Views

953

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

In addition to checking the display property you also need to check the field's value, plus you're missing the "if" part...

Try this:

 

if (this.getField("stock").display==display.visible && this.getField("stock").valueAsString=="") {
app.alert("You must enter at least one stock number.");

}

 

PS. This is JavaScript, not Java. The names are similar but they are not the same thing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

Hi try67,

I have adjusted the script as you suggested.

 

} else if (this.getField("order-stock1").valueAsString==this.getField("order-stock1").defaultValue) {
app.alert("You must select if the unit is in stock or requires ordering.");
if (this.getField("stock").display==display.visible && this.getField("stock").valueAsString=="")
app.alert("You must enter at least one stock number.");

}
The script is accepted and when the order-stock1 is set to default I get the app alert.  When I select Stock and hit submit I dont get the app alert when the required field is empty.

 

I realise writing this that  I did not give an accurate account of the form.  When 'Stock' is selected from the dropdown 4 text fields appear.  'stocknumber1', 'stocknumber2', 'stocknumber3' & 'stocknumber4'.
the text field 'Stocknumber 1' is required to be filled in to submit the form.

 

I have tried to amend the script to below but I am still able to submit the form with no app alert when the 'stocknumber1' field is empty

 

} else if (this.getField("order-stock1").valueAsString==this.getField("order-stock1").defaultValue) {
app.alert("You must select if the unit is in stock or requires ordering.");
if (this.getField("stocknumber1").display==display.visible && this.getField("stocknumber1").valueAsString=="")
app.alert("You must enter at least one stock number.");


}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

Found it.  I needed to write is as:

 

} else if (this.getField("order-stock1").valueAsString==this.getField("order-stock1").defaultValue) {
app.alert("You must select if the unit is in stock or requires ordering.");

} else if (this.getField("stocknumber1").display==display.visible && this.getField("stocknumber1").valueAsString==""){
app.alert("You must enter at least one stock number.");


}

 

Mant thanks for your help, it lead me in the correct direction

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

Try check if field is visible and empty to get alert.

if(this.getField("stock").display==display.visible && this.getField("stock").valueAsString == "") {
app.alert("You must enter at least one stock number.");

}

If you just check if it's visible it will give you alert even if it's filled.

Sorry if I misanderstood you, hope thats what you looking for 🙂

EDIT: I leaved post open so didn't see it was already answered. Wish they have alert for that 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

Hi Nesa,
No problem.  Thank you so much for taking the time to reply.  I realise now that I have not explained the form process very well in my original post.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

Sorry, I now have another question regarding this script.
Is there a way to stop someone filling in a field and then deleting it after they have filled in the next field.
I have just found that I can enter text into a field move on to the next field and go back to a previous field and delete the contents.  The forms will still submit even though the originally required field which contained text is now empty.

Ideally I would like to know if there is a way to make the checking script keep rolling through the required fields and app alerts and if no errors are found it then allow the email script to be actioned?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

LATEST

For some reason this issue is no longer happening after I have saved and closed the from.
After re-opening it, I am no longer able to delete a filled in field and submit the form.  Any deleted field now is required with the correct app alert when the submit button is pressed.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines