jqueryValidation Engine inline ajax validation stopping form submit - jquery-validation-engine

I'm trying to validate a multipart form using the jquery validateEngine plug in.
I can validate the form correctly for all fields however I want to take it one step further and use the built in ajax validation.
I want to check whether a name is unique compared to a database. This function works correctly and I get the expected results however I am unable to submit the form and by running validation in firebug console on the form it validates as false even though all fields are correct.
If I remove the ajax validation the form validates correctly so somewhere in this script a false flag is being set but I just don't know where to look or over ride it
The validation is initialised by:
if ($.validationEngine) {
form.validationEngine();
}
and as I say normal validation works.
I've set up the class in my form as:
class="input validate[required, ajax[ajaxNameCallPhp]]"
The script in the validation engine relating to this method has been changed to this:
"ajaxNameCallPhp": {
// remote json service location
"url": "http://localhost/greenFees/includes/lib/greenFee/checkName.php",
// error
"alertText": "* This name is already taken",
"alertTextOk": "* This name is available",
"alertTextLoad": "* Validating, please wait"
},
Any help appreciated with this issue

Ok - managed to get this to work after a few hours logging the script in firebug...
Anyway. The culprit of sorts is partly do do with another script - form wizard which turns a form into a wizard, it adds a next button which on click runs the validation. For some reason the validation when called from there behaves differently to the form submit.
With the ajax validation it displays a flag if the nameis ok, if it's already used or a notice when validating.
Solution 1:
Remove the wizard script but then the form doesnt behave correctly
Solution 2: remove the notice alertTextLoad - it appears the validation is treating the presence of this flag as an error rather than info - removing it meant I can keep the wizard
Ta

Related

How To Know When A CS Cart Hook Fires?

I need to confirm if I have selected the right hook from the hooks database. I need to auto order a vehicle on confirming an order. I chose the change_order_status and registered it in my init.php using
fn_register_hooks(
'change_order_status'
);
now in my func.php I have
if (!defined('AREA')) {die('Access denied');}
function fn_dellyman_change_order_status(&$status_to,&$status_from,&$order_info,&$force_notification,&$order_statuses,&$place_order) {
//Getting authentication data to identify user
$auth = $_SESSION['auth'];
var_dump($auth);
}
when I go to orders and switch the order from say open to complete, I expect to see the contents of auth rendered to the page at least as part of the request response. However I see no indication that the hook selected is the right one. How can i ensure the hook called is correct.
depending on your CS-Cart version since 4.6.x is Tygh::$app['session']['auth'] but also depend if is done by AJAX request or normal place/edit order
On AJAX request you will not get any notification.
please try to use for a nicer notification:
fn_print_r(Tygh::$app['session']['auth']);
Use
fn_set_notification('W','Description', var_export($varialble,true) );
this gives a notificcation after the hook fires and I found it very useful for my dev purposes.
The W can also be I and E for information and Error. Basically all it does is change the style of the popup

Xpages - Code not executing from radio group due to validators

I have a radio group button, on a page, with very simple onChange code (tried with onClick also) which reads:
try{
print("1");
print("2");
}catch(e){
openLogBean.addError(e,this.getParent());
}
There is a partial refresh with id set to the div containing all my page content. The refresh fires as expected, but the code doesn't run. I have worked out, it is because of validation on other fields, as when I turn validation off for these fields, the code runs.
The question is, how can I get this code to run, whilst leaving validation on for the other fields? I've tried setting "Do not validate or update data" and "Process data without validation" set on my radio group where I want to fire the code, but no such luck. Thanks
Seems "Do not validate or update data" does do the trick, I think my application hadn't built properly first few times around. Leaving here for as an answer for anyone else with similar question
EDIT:
As per Paul's comment below "Process data without validation" will update the server-side and should be the one to use.

Cucumber test for AJAX call testing data has been saved

I have a web page which makes an AJAX call to update data in the database. I want to write a cucumber test to enter the data on the page, triggering the AJAX call, and then verify that the data was saved in the database.
When I fill in selectized with "BP"
And I enter selectized
And Bug "222222" should have tag "BP"
However, because AJAX is asynchronous, cucumber is testing that the bug has a tag before the controller has finished creating the data.
How can I have the test wait until the AJAX call is completed?
You can wait for an AJAX using selenium JavascriptExecutor
example:
public boolean isAjaxDone() {
JavascriptExecutor js = (JavascriptExecutor) driver;
Object result = js.executeScript("return document.readyState");
return result.equals("complete");
}
You need to check for whatever visual change on the page indicates the data has been saved/ajax has completed before checking the database. Sometimes that's a a text message
expect(page).to have_text('Bug Updated!')
sometimes it's a spinner disappearing
expect(page).not_to have_selector('.spinner')
etc. Something like that should probably be the last line of your I enter selectized step.
Note: This issue is one of the main reasons doing direct DB checks in feature tests is generally considered a bad code smell (makes sense in a request spec, etc), and you really should just be checking the information shown to the user.
You could poll for the expected result for a certain time and only fail if it hasn't gotten the expected result within that specified timeframe.

Using standard validation for read only edit boxes?

Some of my recent posts have to do with the fact that I am doing all of my validation in my Submit button.
The reason I am doing this is that I have a button that sets some read only edit boxes. Well you can configure a validation for a read only edit box but it does not execute at run time.
Since I could not figure this out and wanted to have a consistent look for validation I used my own validation on my Submit button.
Is there a way to validate read only fields?
One nice thing about putting all of the code in the Submit button is that all of the validation code is all in the same place but I can see where it also can cause portability issues when using custom controls.
Also another question is how to fire off validation if my Submit button is not marked as a Submit button.
As Dec says, the ReadOnly flag causes the content of the field to be rendered without the <input> tag. This makes validation impossible on the client side and since there is no data being submitted back to the JVM, validation coded on the field is ignored on the submit.
However, the data source QuerySaveDocument is triggered. Put your validation in there and/or put it in the fields that are rendered (readOnly=false) and be sure to set disableClientSideValidation="true" on all fields with validators on them.
Your QuerySaveDocument code looks something like this (assuming location is the field which is readOnly).
if (personDoc.getItemValueString("Location") == "") {
#ErrorMessage("The inherited location is blank and that is bad.");
return false;
}
return true;
With this, the field based validators will fire first and if they are all successful the QuerySaveDocument fires. This means if any field based validators fail, their messages will appear in your message area but the QuerySaveDocument message will not appear. QuerySaveDocument messages ONLY appear after all field based validators succeed.
When a read only field is rendered to the web browser it does not render using <input> tags but rather a simple <span> tag.
Validation can only be performed on proper input tags so the scenario you are experiencing is correct. There is no field for it to validate in read-only mode.
There is an option to 'display disabled in read only' which will render an <input disabled="true"> type tag for the field but I'm not sure off the top of my head is validation will work for those fields either because if a field is read-only then there really should be no need for any validation because your programmatically putting the value into the field and you should be validating it programmatically before you add the value.

How to use Geb to check element attribute value after page event

After a bit of help here, I am writing a functional web test using Geb and want to test the disabled attribute value of an form submit button both before and after an event has occurred, the flow should be as follows:
Load page, submit button is declared as disabled in page source so should be disabled e.g. <input type="submit" class="submit" disabled="true"/>.
Check a checkbox on the page, this should result in a piece of JQuery code executing which will enable the disabled submit button programatically using: $('input.submit').attr('disabled', false);
My first attempt was to use the assertion $('input.submit').#disabled == 'true', this appeared to work for the initial check after page load however after executing my JQuery code to enable the button a subsequent check still returns the same result. This has caused me to wonder if this kind of check is only able to report the value at page load time and doesn't see any subsequent programmatic changes?
I then discovered Geb's jquery itegration, I was hoping I could use this to return the value of the submit button and do my assert on this e.g. $('input.submit').jquery.attr('disabled') == false however the Geb documentation confirms that all calls to the .jquery property return the Geb Navigator instance so sadly I don't think I can return the information I want.
I have also doubted whether the JQuery code was actually toggling the submit button disabled state, I have tested this extensively using Firebug and can confirm that this is working perfectly in the browser, so I suspect this is either an issue with my understanding of Geb or perhaps a limitation of Geb itself?
It strikes me that checking the value of element attributes after performing some action on a page might be a common use-case, hence I'm rather hoping that I've missed some trivially simple way of doing this. Would be most grateful for any pointers to help me get this sorted.
Cheers,
Edd
Have done a bit more testing and have now achieved a satisfactory result. I was doing a couple of things which I now believe are inproper, namely trying to set the disabled attribute value to illegal values of true and false like this:
$('input.submit').attr('disabled', true);
$('input.submit').attr('disabled', false);
Looking at the HTML forms specification the disabled attribute is shown not to take a value, rather it's presence alone indicates that an element is disabled. Modifying my code to honour this and remove the attribute to indicate enablement of an element seems to have done the trick:
$('input.submit').attr('disabled', true);
//This time we remove the disabled attribute rather than setting it to false.
$('input.submit').removeAttr('disabled');
Note: I am still setting the value of disabled to true since I can't determine how to set the attribute without setting a value, see this SO post for further details.
Using the above I am now able to use Geb to assert the disabled/ enabled status of elements like this:
//Check that something is disabled.
deleteSelectedButton.#disabled == 'true'
//Check that something is enabled.
deleteSelectedButton.#disabled == 'false'
Note: Geb seems to require a string literal indicating the expected status rather than a boolean, which iirc caused my assertions to fail.
So that's it - all is now working nicely and I'm running along writing loads of Geb tests! Hope this explanation is of some use to others.
Rebroadcasting my post on the Geb mailing list:
After you execute the jQuery code that enables the button, is it possible that you are checking the result before the code has actually enabled the button? For example, are doing something like:
waitFor { $("input.submit").#disabled == "false" }

Resources