It’s been awhile since a post, but I was on vacation, and then there is the post vacation week of recovery. I don’t have anything big to post, but I figured I’d better post something otherwise I’ll just give up completely on this blog and I don’t want to do that.
So a brief little problem I’ve been working on today is how to do some pre-submit client side validation on a form element in rails if I’m using the remote_form_tag to create my tag. I found a great little solution that was sitting right in front of me the whole time, but it took this article for me to see it. Basically you just use the :before parameter to call your validation script and then just return false if it fails, how great is that. Just another rails solution that ends up being easy as long as you just look at the available tools the right way.
September 28, 2006 at 5:10 pm |
I have been banging my head against this solution all morning, I just cant seem to get it to work.
The following combination of the form_remote_tag, :before, and javascript causes the form to still submit and the action to execute.
Mind to have a look and tell me if I am missing something obvious? I am new to ruby on rails , but relatively adept at javascript, I am hoping I am just doing something blatently wrong .. Thanks! Feel free to email me or I can check back here.
# the form tag
“ValidateForm()”,
:url => { :action => “execute” },
…
) %>
# the javascript
function ValidateForm() {
…
return false
}
September 28, 2006 at 7:34 pm |
your code snippet is a little hard to read, just wanted to make sure you are calling :before => “ValidateForm()” and not just , “ValidateForm()”
October 24, 2006 at 6:13 am |
good site!
November 6, 2006 at 4:42 am |
Thanks Kellybluebook, I’m glad some people are reading it and enjoying it.
September 22, 2007 at 8:01 am |
Hope you come back soon!! notem6715
February 7, 2008 at 11:06 am |
Hi all, by reading the above comments, I thought that you all might have successfully implemented javascript validation before submitting form to a remote action. But when I tried this with my app, I was left unsuccessful.
Below is the code I have.
{:action => “does”}, :before => “validate_form()”, :update => “update_div” ) %> input type="text" name="name" id="name" div updates hereIn my does.rhtml, I am just displaying some text.
this is my javascript code.
function validate_form() { var name = document.getElementById(’name’).value; var errors = “”; if(name != “kishore”) { errors+= “invalid name”; } if(errors != “”) { alert(errors); return false; } }When I enter the correct data, the text is getting rendered successfuly but when data is entered incorrectly, the alert message gets displayed and the request is still getting processed and the div is getting updated with the text. Where am I missing the obvious thing? Any help appreciated. thanks in advance.
Can mail the stuff if the code here is obscure.
regards,
venkat
March 19, 2008 at 9:08 am |
Hello!
I think this try.
September 1, 2008 at 5:36 am |
Good day!,
October 22, 2009 at 12:16 pm |
Acceptance of their results relies on the process of obtain- ing the results as well as analysis of the results themselves. ,
October 23, 2009 at 11:06 am |
Short term employment for youth workers, or even job-creation measures that bring in workers without the proper skills to work with youth, can be counter-productive in terms of creating a successful environment for youth participation. ,