简体   繁体   中英

Submit form and clear value of text field (Rails)

I have a rails form to simply post data and using ajax, reload.

format.js{ render:update do |page|

page.reload

end}

I want to also, clear the value of a textbox inside the form because right now, the textboxes just keep the same value. If they were "hello" and the other was "world", I would click submit, it would run reload , and keep the same textbox values.

EDIT I'm using the default javascripts produced by rails. Prototype.js, application.js (etc.)

Try resetting for form like so:

page[:the_form].reset

You can also update a specific text field value:

page[:foo].value = 'Hello!'

If this is an AJAX call, I suspect the right way to clear the form is in your success callback from the ajax call. If you're using ExtJS or jQuery, this should be pretty easy to do, but without letting us know which JS library you use we can't be much more explicit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM