I'm new to JavaScript, and trying to figure out the canonical way to do the following.
I have a form with some checkboxes and a selector.
Let's say the checkboxes are styles of music and the selector is for people's names.
I'd like the user to be able to select the styles of music for multiple people and then submit the form with all of the data.
For example, the user might first check off Classical, Jazz, Rock, and Pop and choose "Joe", then select Jazz, Pop, Country, and Electronica and choose "Jane". So there would have to be two different buttons for "submit person" and "submit form".
I would like to:
Have a list of the names and their chosen styles populate below the form, for feedback
Allow the user to use the form as much as they want, and then submit all the data at the end
I get the feeling that using jquery and JSON is perfect for this, but I'm not sure what search terminology to use to figure out how to do this.
If it matters, the form will be processed by a Django view in Python.
You can achieve this by using AJAX for submit person. Your work flow should go like this:
User selects Joe and the corresponding styles of music.
User hits 'Submit Person'. On this event, encode the name of the person (Joe) and the styles of music selected into a JSON object and pass it to your back end script via an AJAX (jquery ajax() ) request.
The server side script with do whatever processing it needs to. When it finishes, you AJAX calls' success handler will be invoked. At this point, you can probably remove 'Joe' so the user knows the submission was successful and does not submit for Joe again.
Wash, rinse, repeat for all other people in your form.
PS - when you pass information to the back-end via AJAX, you do not have to encode it as JSON. You can either send it as a standard POST request. To encode a Javascript objects into JSON, use JSON.stringify()
The above is one way of doing it, however it won't work like you asked in your question (keep collecting data - submit at once), To work it that way, everytime the user hits 'Submit Person', add the data to a Javascript object, but do not submit it. The submitted data will keep building up in a JS object.
Finally, when the user hits 'Submit form', stringify the data and submit it.
How about using django form-wizard.. Could it be enough? https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/
Related
I want to add a special widget (e.g. in the start message) which will be have a Submit button. The user interacts with widget, then presses this button and the widget should add a result as a reply message.
The reply form sends a post request with some parameters. Where can I grab it?
Maybe there is a some plugin with such a feature?
I found these props as hidden form fields. I don't know how I missed them at first.
For feeds the similar information is stored in a global variable BP_Nouveau.
console.log(BP_Nouveau.activity.params);
I am making a task list on my site, in which i will put different things to do..
In the end they will be asked to put in their email address and click submit.
Now This is what I want to do when they click submit:
The next day,(not right away!) they should get an email that should
link them to next task.
This should be automatic, and I just have to set the submit buttons
up with the right code provided by you.
It will be my great honor if a volunteer helps me out.
I am also using wordpress
This can be done using JavaScript and Java Servlets.
in action page call: action servlet.
Servlet Should be able to send the email at particular time.
How to send email automatically at particular time of day in javaClick here to see how to send an email at particular time
Try this too
You can't do this with just javascript. You will need that form to post to some back end server which can store the information (probably in a database), and process it at some point in the future when it is necessary.
I know that I can submit form information from a web page by using the #MultipartForm annotation to bind a POJO to a form. (See How do I do a multipart/form file upload with jax-rs?).
What I would like to do, however, is make a Restful call that returns a POJO containing values, and have those values fill in the appropriate form values, which can then be edited and submitted by the user. I know I'd probably need to use JavaScript to first make the rest call, but at that point, is there a way I can use the result to fill in the form?
I could have my rest call return JSON representing the form and use those values to fill in the form with JavaScript, but it would be cool if this could happen automatically, similar to form posting.
Thanks!
I have an MVC app that is basically one page with a bunch of AJAX calls that parse returned JSON and then using jQuery will populate the page. So, for example, if I call /API/Users/List it will return some JSON and then I'll parse that and dynamically create an li element for each user. Then, I put an edit link next to each user name and hook it up to do the necessary editing (jQuery with another AJAX call).
What I'm curious about is how I would go about showing/hiding the edit link based upon role. I have a strongly typed view and can populate hidden fields with user info (<input type=hidden name=UserID value=jsmith /> <input type=hidden name=Role value=Admin />), and of course, can always validate the user in the Controller that the edit action posts to, but, I'd like to know if there is a way to ON THE CLIENT verify that the hidden field hasnt been tampered with so that someone doesn't save the file offline, change the hidden field for Role and then now they can see the edit links when they are not supposed to.
In this contrived example, not much harm comes from being able to see the edit links if they cannot do anything, but there are some calls where I pass the role to an API call and it returns data that is flagged as "private" in the database that shouldn't be seen without the correct privileges.
So, basically, the question becomes "is there any way to exchange data between the ASPX page and the JavaScript that then calls the API without it being just stored in a hidden field that could be tampered with?"
Thanks,
You should not pass the role as a parameter of an ajax call.
The action method itself should determine the role of the user.
I'm struggling to find the best way to display validation messages after a form which has been generated via ajax is submitted.
Let me explain better:
I've got a page that starts with a few options. Based on what the user selects from dropdowns and by adding new fields, the form is created and at the end the form is submitted.
The problem is that, even if I can do validation checks on the server, and display a general validation message on the page. How should I pre-fill the form fields with the values that the user entered before pushing the submit button.
Three options:
normal POST -> the server render the form AS it was submitted (you should be able to rebuild the form server side)
ajax POST -> just redirect the user if validation succeeded
check before post -> synchronous ajax validation calls
There's a couple ways I could see handling this.
1) Do another AJAX call upon submission that does the validations and returns w/o a full post. It's not an elegant solution since it involves two round trips and depending on the validations would lead to performance issues.
2) When you return the json that is used for extending the form, have it instead turn 2 sets of json objects. The first set of objects would represent the data you're currently using. The second set in the array would represent the validation logic which you can then apply however you need upon the form's creation.
Neither way is truly elegant; however, the latter provides a way minimize round trips to do the validation.