jQuery Validation on field(s) with a prefix in the name property - jquery-validate

I'm trying to add the jQuery Validation plugin to some websites and I'm running into a bit of an issue in that the fields that it's supposed to validate have a prefix on the name property, such as "Customer.FirstName".
Since you have to pass a JSON object to the validate function for the rules, it doesn't work because it never finds the elements.
Is there a way to do per field basis, or can I still pass in a variant of the JSON object that specifies the field id as a string, such as "#Customer\.FirstName"?
Thanks in advance!
EDIT:
Per Greg's suggestions, I got it to work. So for anyone who has issues like these, you have to do it like this:
$("form").validate({
rules: {
"Prefix.FieldName": "validationKeyword"
}
});
DO NOT add the "#" to the selector, and DO NOT add the "\\" escape chars to the selector. So, "#Prefix\\.FieldName" will not match anything, so just leave those chars out.

JSON supports keys with "." in them - just quote them:
var obj = {"#Customer.FirstName": "value"};
In fact to be proper JSON they should always be double-quoted.
Edit: if this is a selector then you can escape the . like this: "#Customer\\.FirstName"
Edit2: The docs say the key needs to be a name so I it should either be "Customer.Firstname" or "Customer\.Firstname" depending on how well-coded the plugin is. You'll need <input name="Customer.Firstname" ...>.

Related

Does it allowed to use different name for v-model of input element and validation rule property?

Having trouble with vuelidate.
This is working code with the same nesting level and names for validation and v-model:
_https://jsfiddle.net/submarina/oxsvm5c6/
And here I am using different names for model/validation rule:
_https://jsfiddle.net/submarina/cwhx48q5/
This variant doesn't work too (validation rule is nested, v-model is not):
_https://jsfiddle.net/submarina/gbu9Lkq3/
It doesn't work, you may check $v object.
So the question is why?
Doesn't it allowed to use different name for v-model and related validation rule object?
You didn't replace all occurrences of usernameA to usernameB in both a template and a code (for the second link). I replaced them and it now works like on the first link

Laravel validation; human names for array fields

In Laravel form validation you can do this: file_description.* to validate each item of an array according to a set of rules. The problem is, the system automatically returns "file_description.1 is required" as an error message if the field is required and not filled in.
More on that here: https://ericlbarnes.com/2015/04/04/laravel-array-validation/
Now, I'm not a complex man, I just want the field to say "File Description 1 is required". I am aware you can set messages but a) my input arrays are dynamically generated by jquery (click to add more type scenario) so I'd have to use a loop like in the above example b) I feel like there must be a better way.
Is there a way to either extend the core validation system to simply return a humanized name for the array field as Laravel does with regular fields, or is there an option I missed in the docs that allows for this? I'd rather not get involved with doing some regex type search to fix this.

restful resource's name validation

since i'm using something like http://mywebsite.web/{nickname}/dostuff i was wondering if there's a standard validation for the "nickname" string so that it won't contain reserved characters and stuff like that
I haven't come across any such functionality in Restlet, but what you could do is to get the value of {nickname} in your resource that is handling that URL, and validate it with a regular expression.

Codeigniter active Record

Iam unable to understand following:
$this->db->select('1', FALSE);
Can some one elaborate it in simple way.
The first parameter is the field names or values in your case 1 from your table, the second parameter FALSE prevents the first parameter being wrapped in backticks. You'd use this is you were nesting a sub query as the first parameter.
For further information see the Codigniter docs which are incredibly useful.

jQuery POST and GET methods: Construct URL or use data param?

I am using the post and get methods for Ajax calls, and have a general question. There are two methods I've seen people use on the web:
Construct the URL and parameters by
hand
Use the data parameter
Both approaches work. I've included them below:
// Construct the POST URL by hand
queryStringDelimiter = "?";
settings.queryParam = "q";
$.post(settings.url + queryStringDelimiter + settings.queryParam + "=" + query, {}, callback, settings.contentType);
// Use the data param
$.post(settings.url, {q:query}, callback, settings.contentType);
Are there any situations where you would construct the URL and parameters by hand instead of using the built-in data parameter? Any advantages of one method over the other?
I'd say the data approach is better since it formalizes the process and reduces the chances of producing errors while string building. Besides, the JQuery library will do the string building for you so its basically the same amount of work.
No reason I can think of why one would construct them by hand unless they didn't know of the data parameter if there's more than 1 or 2 parameters, it's also cleaner to keep them separated so if you have to loop through the data object and possibly modify some values you'd just iterate over the object instead of parsing a string manually.
If you let jQuery concatenating the data in to the appropriately formatted string you...
avoid having to duplicate that code...
avoid worrying about escaping the data for transport...
can easily switch between GET and POST requests in the future...
Really, the only argument AGAINST using the data parameter is if you already have the data in a concatenated format.
If I am using a GET I tend to just construct the URL, but when using POST I use the data parameter.
I do it because it is closer to how I was doing ajax calls before jQuery, when I wrote everything myself.

Resources