Validating URL in dojo textbox - javascript

While trying to validate URL input by user in ValidationTextBox but there is nothing I could find for validating URL input like "www.google.com" and "http://www.google.com"
<input dojoType="dijit.form.ValidationTextBox" regExp="dojox.validate.regexp.url" tooltipPosition="below" required="true" placeHolder="Enter Rule url" type="text" name="ruleUrl" id="ruleUrl">
The above doesn't work. Any alternative for validating URL's?

Are you sure you added dojox/validate/regexp to your modules in a require()? Because the code seems to work perfectly. I also made an example JSFiddle.

Related

Auto-Complete Off is not working in Chrome

I am trying to disable google password autocomplete field in password text-box in chrome browser. I tried autocomplete off but that doesn't work then I tried auto complete : "new password" that also doesn't work. Suggest me any solution for this problem.
Thanks in advance.
here is my code
i tried
autocomplete="new-password"
I've tried to disable it -- at this point only thing i the autocomplete='off' doesn't work
i would try this --
set the password box with a value on the pageload
$("input[type='password']").val(" ");
on focus set the value to empty
$(document).on("focus","input[type='password']",function(){
$(this).val('');
});
For this you can use a trick. Chrome always track first <input type="password"> and the previous <input>. So add this:
<input style="display:none">
<input type="password" style="display:none">
To just after <form> tag started and the case will be resolved.

Programmatically input angularjs text field using javascript/VBA

I am web scraping from AngularJS application using Excel VBA. I am trying to enter value in text-input by using something like- ie.Document.getElementsByTagName("button")(15).Value = "112233"
I also tried- ie.Document.parentWindow.execScript "document.getElementsByTagName('button')[15].Value = '112233';
None of them is working. I have search few other posted questions but problems still exists. The element is:
<input whole-number="" type="text" maxlength="20" class="......" ng-model="pList.pNumber" bs-typeahead="typeahead_ProjectNumber" placeholder="enter a value" data-provide="typeahead" ng-change="reduceScrollMax()">
I got the solution to the problem:
angular.element(document.getElementByTagName('input')[15]).scope().pList.pNumber = '112233';
followed by
angular.element(document.getElementByTagName('input')[15]).scope().$apply();
OR angular.element(document.getElementByTagName('input')[15]).scope().$digest();
Include the above mentioned in ie.Document.parentWindow.execScript "..." to run it using VBA.

Trouble adding data-parsley-pattern programmatically

I'm using Parsley, and it's great! I want to add different validators programmatically, depending on locale, using javascript/JQuery. When I hard-code like so:
<input type="text" id="billingPostalCode"
name="userInput_billingPostalCode"
value='<c:out value="${param.billingPostalCode}"></c:out>'
class="form-control" required=""
data-parsley-pattern="^\d{5}(?:[-\s]\d{4})?$"
data-parsley-error-message="Valid Zip/Postal Code Required"></input>
it works great. However, when I try to add it programmatically, it doesn't. I have this in a .jsp file:
<input type="text" id="billingPostalCode"
value='<c:out value="${param.billingPostalCode}"></c:out>'
class="form-control" required=""
data-parsley-error-message="Valid Zip/Postal Code Required">
</input>
And this in .js:
$('#billingPostalCode').attr('data-parsley-pattern', "^\d{5}(?:[-\s]\d{4})?$");
The attribute gets added (I can inspect the element and see it), but it doesn't validate correctly (it sees valid input as invalid). I have tried placing the JQuery code both before and after attaching parsley to the form:
[here...]
$('#paymentInfoForm').parsley( ... );
[and here...]
I have also experimented with the regex, anchored and unanchored, simplified versions, etc. But like I said, the regex works perfectly when it's hard-coded.
Could there be some interference with JSP? Am I missing something? Thanks in advance.
I worked around this by using [0-9] instead of /d in my regular expression. It does seem to be a bug, though. This works as expected:
$('#billingPostalCode').attr('data-parsley-pattern', "[0-9]{5}(?:[-\s][0-9]{4})?");
but the following code not won't validate anything, and will even break hard-coded validation:
$('#billingPostalCode').attr('data-parsley-pattern', "\d{5}(?:[-\s]\d{4})?");
The problem must be specific to javascript, since it works when hard-coded into the jsp file.

Validate generic input using this in Javascript

I have a html form full of inputs and I'd like to validate if it has no content using change event. I wanna do something like "when I tab this field, focus it and put a a sign if it be empty".
Try required validation:
<input type='text' required value="some text">
This may be sufficient.

Long form validation in JavaScript / jQuery

I have a long long long form. It has about 200 fields. Now, about 50 fields need to be validated through JavaScript / jQuery. How can I easily validate them without a huge amount of code. I want to avoid doing this:
field1 = document.getElementById("field1").value;
if (field1 == '') {
alert ("Please enter a value for Field1");
return false
}
Is there an easier way? Thanks a lot.
Use the jquery Form validation plugin and assign the correct classes to the fields.
It's as simple as class="required" in most cases!
If you just want to check if the field is empty or not you could do something like this using jQuery:
HTML:
<form>
<input class="validate" type="text" />
<input type="text" />
<input class="validate" type="text" />
<input type="text" />
<input class="validate" type="text" />
</form>
SCRIPT:
$('.validate').each(function() { //this will get every input marked with class "validate"
if ($(this).val() == '')
return false;
});
Using JQuery validate plugin can be much help. You can control the way plugin works from your HTML code and even not write any javascript! If you need more complex validatio, you can extend it by adding specific validation functions. It allows you to localize the application as well.
This page gives a good example on how to use the plugin: http://jquery.bassistance.de/validate/demo/milk/ (click the "Show script used on this page" link).
Here is a rudimentary fiddle, that you can use to validate your form, Just add a span after each of the fields that you need to validate.
http://jsfiddle.net/refhat/h2S6G/35/
I thought about this too, but the plugin can be a bit difficult to
use. Do you know if it allows to display an alert box when an error is
found, instead of the actual displaying on the page? That's a bit too
much for this form. Thanks a lot
Here's a validator I wrote that uses a pop-up style alert box for error messages. Is that the sort of thing you are after?
http://validator.codeplex.com/
Do you want default error messages like for required validator? Regarding jquery validate plugin was it the syntax it offers to place validation information in the method call you found difficult since for a large form having validation information located separately from the text boxes makes it harder to go through and verify all fields have the right validators and messages?

Categories