loading html FORM asynchronously and adding it into DOM does'nt get validated by jQ validation plugin - forms

A simple get request made to url on my server which returns HTML of form which is put inside td element .
$('form').validate(); // jquery validation plugin initialized
//user clicks some button and ajax request is send to load form
$.get(url,send,function(form){
$('td').html(form).show();
});
Problem is validation plugin do not work on the loaded form ?

The form you are trying to validate does not exist when you initialise the plugin. Place the initialisation code in the success handler of the $.get(...).

Related

Allow form submission to server inside of angularJS?

According to the AngularJS doc's https://docs.angularjs.org/api/ng/directive/form
"For this reason, Angular prevents the default action (form submission to the server) unless the element has an action attribute specified."
is there any way to stop angularJS doing this?
If you don't want the form submission to go down the browser handled route don't put the action attribute on the form use the directive ng-submit which basically calls a method on your controller which will allow you to send the data to the server via a xhr request.

How do you access javascript from selenium and submit a form?

I have some html that uses JS to submit a form:
<form onsubmit="doform();return false;">
In the test script I'm doing the following based on what I found here on SO and in
the WWW::Selenium docs.
$sel->get_eval("this.browserbot.getUserWindow().doform()");
The normal form submission works fine but it does not work in the selenium code.
If I scoop the JS out of the js file and make a string in the test file it works fine.
my $js = "{ //do some javascript stuff here; }";
$sel->get_eval( $js ); // this works.
I'm under the impression that that is not the correct way to do that though. It's certainly
not desirable, especially when the function calls other functions.
What is the correct form for using selenium to submit a form?
There is a method to submit the form (which should also fire the onsubmit javascript).
From WWW::Selenium:
$sel->submit($form_locator)
Will submit the specified form. $form_locator is an element locator for the form you want to submit.

Can I access the function body of an event listener using nodeJS jsdom

I am using jsdom with nodeJS. I load in a large HTML document, and am using jQuery to navigate the DOM. I have a case where I have an element, and I need to access the function body of an event listener (onclick). The event listener was added in the source HTML:
The onclick attribute of the DOM element is undefined.
btw: what I really want to do is get the URL (please note that <rest-of-url> is not what is in the source, a real URL spec is there) that is specified in the source.
e.getAttribute('onclick') doesn't work?

issue in Zend_Frame_ Select box validation in ajax call

i have created a country select box as
$country= new Zend_Form_Element_Select('country');
in my user registration form ..
While selecting an country an ajax call is send and getting the state list
by creating another select box
$state= new Zend_Form_Element_Select('state');
in another action say stateAction()
Problem is that when i tried to validate registration form in the POST action
i cant retrieve the value from state
$form = new Users_Form_Register();
eg as $userObjectDetails->statename=$form->getValue('state');
as a solution i added tried to added a dummy variable $state in Users_Form_Register();
add addElement($state),unfortunately during value is loaded by ajax call the state list issue occure during validation of the form
please suggest a solution for the above
Thank you
You could try validating with javascript. jQuery has a nice validation plugin that lets you attach the validator to the form ID and define the rules you want to validate.

How to use MicrosoftMvcValidation with jQuery.Ajax in ASP.net MVC2?

using asp.net mvc2, Data Annotations,
MicrosoftAjax.js,MicrosoftMvcValidation.js,
jquery for ajax
I have contact form and i am using Data Annotations for the ContactFormModel.
I add this line <% Html.EnableClientValidation(); %> to top of the form.
When i click the submit button client validation works perfectly. Now i have changed my mind and want to post the form with jQuery.Ajax.
This time i want to accomplish this.
Click submit button.
MicrosoftMVCValidation does the client validation and renders the errors on the clientside.
If Model is valid i meant if the validation passed i want my jQuery ajax to get involved.
But when i clicked the submit button both ajax post and mvc client validation works.
How can i get the things in right order.
1.Mvc Client validation
2. Then jQuery.Ajax Post.
var myForm = $("#MainForm");
var formContext = myForm[0]['__MVC_FormValidation'];
var errors;
if (formContext) {
// validate the form
errors = formContext.validate("submit");
}
if (!formContext || errors.length == 0) {
// no errors so submit to server
...
}