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

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

Related

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.

Laravel - Model binding not working when I use accessors

I want to populate my select box from the Laravel IoC Container.
App\Http\Utilities\BillingHelper.php
views/billing/create.blade.php
views/billing/edit.blade.php
Create the table:
Now, instead of the value, i want to display some flags and currency symbols.
Should i use mutators?
Problem
If i use mutators, when i open the edit page, i see always the first value selected, from the BillingHelper, instead of the choosen one.
Any help? Thanks.
I know it should be a comment, but I have no reputation.
What if, on you edit page, you replace null on Form::select with $client->language and $client->currency.
I know that you area binding the values with Form::Model. But worth a try.
When you use mutators the matching won't occur anymore. You'll have to use a matching static array according to the values you'll return. (the flags)
You can make it work if you make a mutator for saving the data also and simplify again to the ['it', 'en', 'lv'], otherwise your saved data will differ and the initial mutator won't work the second time. You can still make a one-time-only test.
This is why:
Your form binding is using $bill->language to retrieve the actual stored data, and compare it with the values in your $bill::lang static array. If no match found, than the first value will be always selected.
Can you provide the the currency and language fields definition in the migration for the bill?
Also retrive your values from your bills DB and paste them here for language and currency. They must be in the defined static sets.
Laravel has a way of skipping the accessor/mutator by using
$model->getOriginal('data_field').
The "getOriginal()" gets the model's original attribute values.

Using the Codeigniter form validation library, how can I ensure at least one letter is entered?

I am using Codeigniter form validation. In my registration form the Username field allows only numbers like 123456. I don't want this to happen.
My validation rule is as follows
'rules'=>'trim|required|alpha_numeric|min_length[6]|xss_clean'
I want to prevent users entering just numeric strings. Alpha numeric strings are fine, alpha strings are fine, but purely numeric ones are not.
To allow only letters
Add alpha to your rules and remove alpha_numeric from your rules
You can use this page as a point of reference for built in validation rules.
Edit:
Since you've clarified now.
To achieve this, there's no built in validation rule. You will need to extend the Form_validation library by creating a libraries/MY_Form_validation.php file. See this manual page on how to extend libraries.
In this file, create the following function
function at_least_one_letter($string) {
return preg_match('#[a-zA-Z]#', $string);
}
Then you can add the validation rule at_least_one_letter to your rules.
According to the codeigniter user manual :
You can also use any native PHP functions that permit one parameter.
I think in this case is_int could be used as your validation rule.
So, for instance:
'rules'=>'trim|required|is_int|min_length[6]|xss_clean',

What's the best way to pass additional POST variables into a validation rule in Kohana 3?

I'm trying to validate some POST data. One of the validations I need to do is a registration code, which is based off another POST variable - an IMEI number.
In my POST data I have 2 fields, register_imei and register_code. My code currently looks like this:
$post = Validate::factory($_POST);
$post->rule('register_imei', 'not_empty')
->rule('register_imei', 'exact_length', array(15))
->rule('register_imei', 'some_class::luhn_check');
$post->rule('register_code', 'not_empty')
->rule('register_code', 'some_class::valid_registration_code', array($_POST['register_imei']));
However, I'm not sure whether passing in the variable from the raw POST array field is ok, because it could be empty or not set. Does the fact that I've already added validation rules for register_imei above make it safe?
Does the fact that I've already added validation rules for register_imei above make it safe?
No validation is taken place until you call the check() method.
To solve your problem, use:
Arr::get($_POST, 'register_imei', NULL);
which returns the 3rd argument as a default if the key is not set in the array.

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

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" ...>.

Resources