Submit button with required fields notification.
Hi, I have a very limited knowledge when it comes to writing scripts so please consider this when answering. I have form for managers where they have to fill up information about sales and production every day. There is about 20 fields in a form and all are required. I have found how to write it for one field but what if I have many? Looking for some simple solution when they click on submit button and if some required fields are not filled it will show message which fields are not filled (or even message “fill up required fields” is enough) and it will prevent them from closing the form until everything is filled.
27 replies
-
You don't say if the users are filling out a dashboard/page or creating a record directly in the table.
I'm going to assume that you are using a dashboard since you always want to limit direct user interaction with your data.
You can put the following code in a button:
Line 1: takes the current record and puts it in a variable "t".
Line 2: creates a variable that stores a carriage return
Lines 3 - 5: shows how we check three fields for a null value. We check to see if the field is empty and if it is then we assign a value of 1 or 0 if it is full. You will need to create a line for each of the field you want to be required.
Line 6: creates an array of the "-check" variables above and stores it in a variable.
Lines 7 - 31: is the heart of the code. Since we have an array of numbers we can do some fancy stuff with it. Line 7 starts us off checking to sum of the array in Line 6 and if it is equal to 0 (meaning all the fields have data in them) then we can create a new record in the appropriate table (change the table name to match your situation. We even pop up an alert to tell the user a new record got created.
Line 15 starts the part of the code that jumps when if the sum of the array is not equal to 0. Here we create an alert that will list all of the fields that are empty. The important thing to learn here is the escape characters:
Why are they needed? Well an alert() command normally just takes whatever you type in between double quotes and displays it. Well we need to "escape" out of the quotes and tell Ninox to run some code then return to the display something else.
So we start our alert() with:
now we have to escape out to run some code. So it will look like:
Notice I put both opening "+ and ending +" in so I always know that I closed things properly and just have to make sure I put the code in between. The first field looks like this:
This formatting is done by Ninox so I've kept it. We will now check the array we made above to see which fields are empty and need to be reported to the user. We will use the item() command. The first property in the parentheses is the array you are checking. The second property is the instance you want to pull. Like all other programming language the first instance is 0 and goes up from there.
Line 2: we get the first instance of the array with the item() command and check to see if it is equal to 1 (meaning it is empty) and if it is then we print the variable that stores the carriage return and the name of the field.
Now how do we add another field? Take a look:
You want to make sure you don't put a carriage return after the double quote on lines 5 and 9. Otherwise you will have too many in the alert. So you can just copy a section then paste it and then change the number in the item() command to the next one and then change the text to match.
I've attached a DB. Open the Dashboard then click on the Field Check tab and you can see it in action.
-
Hi Fred,
Thank you for your response!
There is a problem, it kind of creates two records when I click on the button. Please see the picture, in one record it has selected the Shop and in second it does not, both those records were made when clicked on the button.
did I adjust the script correctly?:
also is it possible to remove cross option to close the form
-
said:
There is a problem, it kind of creates two records when I click on the button. Please see the picture, in one record it has selected the Shop and in second it does not, both those records were made when clicked on the button.There is nothing in the code that tells Ninox to create two records. Can you post a sample DB, with dummy data?
said:
also is it possible to remove cross option to close the formIf you remove the close button how would close the record and return to the Create Reports form? I'm guessing you clicked on a record from the View element in Create Reports, so Ninox opens a new subwindow so you can see the record you clicked on. But Ninox needs to allow you to return to the original table, thus the close button.
-
Hi Fred,
I don't understand what you mean "to expand the list of fields that you copy, Shop being one of them." do you mean i have to first add all the required fields in the formula? And then it should work?
-
Hi,
i understand how to add all the fields in the formula. But I do not want our shop managers go into each table with records. So I have created separate view where they select between three different records Daily sales report, Hanging Production report, Pricing production report. Under each they will find button create report and it opens the entry form. When I click on create report it automatically creates empty record and when i start to fill up data it all goes into that record so until this point everything is ok. But at the end of the entry form is button to "submit record" (i need this as We have problems with managers forgetting some fields to fill up and makes me crazy when I need to evaluate statistics so I need them to be forced to fill up everything) so when they click on that submit button it creates one more record with the same data.
Anyway I think I found the issue, now I have removed from script the part that creates the record so it only pops out the message, and it does not create two records.
What makes me still worry, they will find reasons why not to fill it up all fields despite they get message from button and use the cross to close it. This is why I asked if it is possible to remove the cross and if it is possible to close the entry form when clicking on submit button when everything is filled up?
-
I believe i did not describe it properly, as I am very new to this. But it still will help as for now they at least press the button and see what is missing.
So just to make sure I understand correctly, in the dashboard I will create new fields with same names as are in the table for Daily sales (where are kept all data) and in the submit button to have script that enters data from dashboard fields to Daily sales under condition required fields must be filled in?
All fields will be required
.
Do you know if there is created topic where I could see how the script goes for this solution? Or what to exactly ask if I post topic for this issue? I am trying to look for something to this issue but cannot find anything.
How would i connect field "Turnover" in dashboard to field "TURNOVER" in table Daily sales by clicking on button submit? Just give me a kick start...
-
Thanks it works!
I have still one more question. Everything is filled up, click on button and data is uploaded to correct table. Is it possible so the fields in dashboard get empty so new record can be made?
-
it shows for the newfield1 "end expected
-
still doesn't work, maybe i dont place it correctly?
-
still doesn't work
-
I have managed to create button for clearing the fields and works. See the script, any chance this could be somehow put into script for button to submit record?
-
For some reason it displays only first four fields, if the rest of fields is not filled in it will submit the report anyway. Is there something written wrong in the script?
-
i have made one more button for another report, but has the same problem as with button for DAILY SALES, when i add at then the part to delete information from field, line 127 it shows problem. Any chance you could look please what I am doing wrong? I have used null or 0 according what you wrote before.
Content aside
- Status Answered
- 3 mths agoThu, December 26, 2024 at 2:55 PM UTCLast active
- 27Replies
- 409Views
-
5
Following