I used to use PHP before and I get why forms are so common because it could literally make you submit a page and request a page from the server through a method that you would choose ( POST / GET ... ) . But when I made a transition to vue. I felt like using them wasn't the same since I already have Axios to get all the values from my APIs and I'm using an SPA so I wouldn't call an entire page from a server like PHP but just grab the components I need and modify the page according to my needs ( the page is dynamic ) I didn't get why I would use form since the action and method attributes aren't as useful as they used to be in PHP and I could just do all I need on a button with a type of button and get my info to the other components. And even if we were talking about a non-SPA app, it would use this.$router.push to get to the next page and you can even pass in the values in the link on a button click with a type of button and not type submit.
So my question to wrap it all up is how are forms used in Vue. Is it a common practice to use them ? The only thing I know is that it gives semantics.
Related
I want to know if it is possible to directly modify and save a model instance in the HTML Template and not via a view and extra URL.
My user has a Boolean Property, I want to display it as a toggle button on the website and the user should be able to toggle it on or off without leaving the website or reloading it.
class User(AbstractBaseUser, PermissionsMixin):
...
autoplay_enabled = models.BooleanField(default=True)
...
Is this possible without an extra view or form?
Basically I just need to set
request.user.autoplay_enabled = False (or True)
and then save() it
If I can't modify the object directly in the HTML template is it at least possible to just execute a function I have defined somewhere in my Python code, without having the need to create a new view?
What you're asking doesn't make any sense at all. HTML is just sent to the browser for display. You can't do anything "from HTML" without making some kind of request to the server, and the server won't do anything unless that request is received by some code - eg a view connected to a URL.
If you want something to happen without refreshing the page, you need to use Ajax. You can use a simple Ajax POST to a view that toggles the value and saves it - it only needs a dozen lines of code between front and back end.
We are trying to implement a web page that each time of page refreshing will not result in the form resubmit, how to achieve that? Is there any Javascript code or HTML can make it WITHOUT external javascript library(jquery, dojo or extJs)
The reason of such design is that the form is going to tie an unique relation to current data with means cannot do it twice but for security reason we have to use POST instead of GET, also after the action we still want to preserve user the right to do similar action on the same page to another relation. so how to avoid a consequence like that?
Thanks.
Suppose that the action to the form submits it to submit_form.php. That file can handle the data and do whatever it needs to do. Then in it's response, it can redirect the browser to a separate page (you'll have to look up the exact method of how to do this depending on what language you write your POST handler in). This separate page can show the results of the form submit using session variables or some other method.
I've got the following problem: I made a js that generates multiple hidden fields with the same name (in this case 'vak')
I want to be able to post all that data to a JSF method so I can write it to the database.
Thing is, I want to do this without binding the data to variables in the controller
in short, I have a save button that serializes a form(with js generated fields) on click
vak=0&vak=1&vak=2&vak=3
I want this to end up as an array(list) in the JSF controllers method "handleSave()"
EDIT: this can be closed. I ended up doing it the proper way by handling each change to the calendar as an ajax request and the js just be in charge of the rendering
You can get all parameter values by ExternalContext#getRequestParameterValuesMap().
String[] vak = externalContext.getRequestParameterValuesMap().get("vak");
You'll only need to write some boilerplate code yourself inside the action method in order to convert, validate and update the values (which is what JSF would basically already be Do for you when used the right way).
I have the following scenarios:
User will input some value , and this values will be validated against the value from DB in the action class.
If if the value is invalid, want to show a confirm box to the user whether he still want to proceed with the invalid value.
Depend on user's answer YES or NO, which is brought back to the action class, the process of the action class will be different.
For the above scenarios, step 1 is OK.
But how do I achieve to bring the value from the action class to the javascripts and getting user's confirmation and bring back the value to the action class?
The second approach can be done by using Ajax. Struts 2 provides many ways to use Ajax:
Use the "stream" result type to send data back to your JS code.
Use the JSON plugin to get JSON back.
Consider the Struts 2 jQuery plugin.
A Google search will give you a lot of examples as how to use Ajax with Struts 2.
I'm looking to capture and save the state of a page (Django template + backend) after the user makes some modifications (through JQuery) to the appearance of the page. Now that I've gotten hold of the innerHTML using a JS variable, I need to send it over to the Django view that will do the saving. How do I call this Django view and pass it the JS variable?
P.S: First ever question on stackoverflow, please let me know if the question isn't clear or is improperly formatted.
Handiest way to get started is to first make a proper form and a django view that reacts to it ("request.post"). The form should have fields for whatever you're changing in the page.
Next up, submit that form's variables from your page with jquery.ajax.
So the idea is to isolate the various problems:
What should be the form parameters?
Get a view running that makes the actual changes.
Get the javascript working.