UnhandledPromiseRejectionWarning: Field was not found by text|CSS|XPath - javascript

I am very new to coding and I am stuck at a place where I am trying to add some text to a field. The code is written in Javascript and we use Puppeteer as a helper. When I try to click on the field with the same locator, it clicks just fine, even when clearing the field, it works fine. The only issue is happening when I am trying to fill the field, at that time it is not able to find that field with the locator specified, not sure what is going on there.
Here is the code and the run results. In the code, after the pause statement, it is failing.
// View Trial Level Form
clinicalTrialsDashboard.openATrialLevelForm(common.trialLevelFormEditAccess);
within(patientInteraction_po.fullPageModalHeader, () => {
I.dontSeeElement(patientInteraction_po.formSettingsBtn);
I.seeElement(patientInteraction_po.auditHistoryBtn);
I.dontSeeElement(patientInteraction_po.queryModeBtn);
I.dontSeeElement(patientInteraction_po.printBtn);
I.dontSeeElement(patientInteraction_po.investigatorFlagBtn);
I.seeElement(patientInteraction_po.closeForm);
I.seeElement(patientInteraction_po.saveForm);
I.dontSeeElement(patientInteraction_po.saveAndComplete);
//I.fullyClearField(patientInteraction_po.trialLevelFormInput);
I.pause();
I.fillThisField(patientInteraction_po.trialLevelFormInput, 'dddd');
I.waitClick(patientInteraction_po.saveForm);
I.waitForHideForLongTime(common_po.loadingSpinner);
I.see(common.alertMessage);
I.see('Trial Level Form Saved');
I.waitClick(common.okayBtn);
});
Result:
I.
I fill field {"css":".scheduled-form-display [data-c^="form-question"] [data-i*="input-element"]"}, "dddd"
(node:11479) UnhandledPromiseRejectionWarning: Field "{"css":".scheduled-form-display [data-c^="form-question"] [data-i*="input-element"]"}" was not found by text|CSS|XPath
Thanks.

Related

jQuery validation plugin - how to style 1 validation message differently to others

I have a form that is being validated with the jQuery validation plugin successfully.
Messages are displayed in the correct position and in the correct situations.
So far, so good.
I have 1 field that is being validated correctly, but I need to position that 1 validation message differently to the others. With 2 inputs next to each other, I want the validation to appear under them both (ie under the block that wraps them both) rather than to the right per individual inputs.
The validation on these 2 inputs are dependent on each other, ie at least one must have input. The validation rule works, it's just the positioning I'm struggling with.
I'm using the following validation syntax:
$('#formId').validate({
rules: {
},
messages : {
}
}
In my HTML I have created a label specifically for the (radio) field I am trying to customise:
<label for="radioName" id="radioNameId-invalid" class="error"">Some error message</label>
I tried adding content to the 'showErrors' function of validate, which works, but seemingly then doesn't show any of the other validation messages in my page.
showErrors: function(errors) {
var collectionMethodError = errors['collectionMethod'];
if(collectionMethodError) {
$('#radioNameId-invalid').text(errorString);
$('#radioNameId-invalid').css("display","block");
}
}
I want to enable this error AND then allow validator to continue to do its default behaviour for other fields.
If I remove the showErrors function, the other validation messages are displayed but not my custom one.
How can I get both behaviours?
I ended up using the errorPlacement function instead of the showErrors function:
errorPlacement: function(error, element){
$(error).insertAfter(element);
// special case for display
if($(element).attr("name")=="radioName") {
$(error).insertAfter("#anElement"));
$("label[for=radioName].error").attr("id","invalid-radio-message");
}
}
So in short I'm adding an ID to a label that validation plugin adds, then styling to that ID in my css.
That seems to do what I was trying to do. Now to workout the re-hiding of the message!

Mvc Telerik grid cancel cell changes when input invalid

I am facing a small problem regarding input validation in mvc telerik grid.
I have it set to batch editting and I'm modifing the cells in an InCell mode.
Now whenever a user enters an invalid value in one of the inputs(Telerik's comboboxes/autocompletes), I'd like to display a message that
the entered value is iligal(this far I've managed on my own).
In addition to the message I'd like to revert the cell's value to it's previus value before
the user input.
So far I've tried:
grid.CancelCell(this);
$('#grid .t-grid-edit-cell input[type="text"]').value or innerText = prevVal;
The closest so far was e.newVal = e.oldVal, although it sometimes throws me a wierd exception in the jquery scripts or displays the combobox's drop down.
All the validatios and things I've tried are from the grid's client event OnSave()
It's same like what i searched before and I have solution for you.
On your OnSave() method has event like OnSave(e) and that 'e' carry all the elemnts and functions inside in my example after validation if not ok i can change that value to old value. Also you can use inspecter element log to look up what is inside 'e'
function onSave(e){
if(!validation)
{
///
}
else
{
e.cell.firstChild.value = "0"; // that is my edited cell
}
}

Unable to change minLength dynamically

I have a dropdown which has countries and in the same form on 2nd line I have ZipCode texbox. I want to limit the minLenght of the zipcode field dynamically. For example If US is slected zipcode should not be less than 5 and for other countries some other minLength Limit. My form uses a parsley validator
I wrote below function onChange event of my country dropdown
function setZipLimit() {
alert("in Zip limit" + document.getElementById("billingCountry").value);
if (document.getElementById("billingCountry").value == "US") {
alert("I am in US");
$('#billingForm').parsley('destroy');
$('#billingPostalCode').data('minlength', 3);
$('#billingForm').parsley();
} else {
$('#billingForm').parsley('destroy');
$('#billingPostalCode').data('minlength', 10);
$('#billingForm').parsley();
}
}
But this doesnt seem to be helping. Can you please help me?
You cant just edit the Attribute, because parsley.js initially Reads the form and gets its Values. Changing them Afterwards shouldnt have any Effect.
However you can use the Parsley.js API for Javascript functions to Edit the constraints. You already used them to destroy and Build Parsley. Parsley got the following Function:
$( '#field' ).parsley( 'updateConstraint', { minlength: 6 } );
There are also some with addConstraint and removeConstraint in the Documentation:
http://parsleyjs.org/documentation.html
If your Form gets more complex and you have several of those dynamic cases, i recommend to only Destroy and Rebuild specific Parts of your Form. The Reason is (from an issue I had recently):
If you Destroy Parsley, change some Fields, build Parsley and then Destroy it again because another if Statement takes place, your previous Changes get thrown away, because Build only reads the js inbetween the Destroy and Build and reads the Form.

Using JQuery MaskInput Plugin with a SSN Field

I am trying to use the JQuery MaskInput plugin on a SSN field but I dont see anyway to make it display "***-**-****" after the user leaves the fields.
Did anyone get this working>
I havent tested this, but it may get you headed in the right direction. The masked input plugin has a completed function that can be called when the user has finished entering their value. You can use it to grab the value and store it in a hidden field to retain it and replace the current text with whatever you desire.
var $txt_SNN = $("#txt_SSN");
$txt_SNN.mask("999-99-9999", {
completed: function() {
$('#hdf_SNN').val($txt_SNN.val());
$txt_SNN.val("999-99-9999");
}
});
$txt_SNN.mask("999-99-9999").blur(function() {
$(this).attr('type', 'password');
});`
This should do it. Although I didn't test it.

HTML5 Form Validation

I have two major problem regarding HTML5 form validation.
1- I use this code to change the validation message of inputs
$$('INPUT').each(function(input)
{
input.oninvalid = function(event)
{
event.target.setCustomValidity('');
if (!event.target.validity.valid) event.target.setCustomValidity('Please Fill');
};
}
There's a big problem with this method. As the form is submitted if the input is invalid, an error message is attached to it. So it wouldn't validate on new input. Even after correction and submitting again it won't let the form get submitted because the message is still attached. so event.target.setCustomValidity('') will remove the message and form needs another submit. two submit after correction.
I couldn't find a way to correct this behavior.
2-How can I hide or disable these tooltips totally but still use form validation. Sometimes I want to use css invalid and valid pseudo classes, but these tips are still displayed.
I find formnovalidate on submit button and then I can check validity.valid of each inputs manually before submitting. any better idea?
In terms of question 1:
I had an input
<input name="VoucherCode" id="VoucherCode" type="text" pattern="(1[0-9]{9})|(2[0-9]{9})" value="">
And improved the default message
$("#VoucherCode").on("invalid", function (event) {
event.target.setCustomValidity('The format of Voucher Code is not correct.')
});
But this had the same problem you encountered: if the user gets the first attempt wrong, a correct response still show the invalid pattern message.
I fixed this based on #Pointy's suggestion:
$("#VoucherCode").on("invalid", function (event) {
event.target.setCustomValidity('The format of Voucher Code is not correct.')
}).bind('blur', function (event) {
event.target.setCustomValidity('');
});
(a bit late) but the solution could be around there!
What happen:
Since you customize the error message event.target.setCustomValidity("...") the property in the element.validity.customError is true ; the reportValidity with always return false and the submit wouldn't be valid
What I did?
When the User change the input (event.on Change) - I set up back the default error message event.target.setCustomValidity(''); this will tells the Browser to keep working without a custom error

Categories

Resources