In model.json file I try to give validation property to array as per document says but it doesn't work .. (I want validaions by validations prperty only)
How to give validations array ?..
also see i tried as per in screenshort but that didn't workenter image description here
I am new to Loopback but the current (v3) documentation states:
Warning: This is not yet implemented. You must currently validate in
code; see Validating model data.
For now you have to put your validation code in the model's JS file.
This is the example given in the documentation:
common/models/user.js
module.exports = function(user) {
user.validatesPresenceOf('name', 'email');
user.validatesLengthOf('password', {min: 5, message: {min: 'Password is too short'}});
user.validatesInclusionOf('gender', {in: ['male', 'female']});
user.validatesExclusionOf('domain', {in: ['www', 'billing', 'admin']});
user.validatesNumericalityOf('age', {int: true});
user.validatesUniquenessOf('email', {message: 'email is not unique'});
};
This is reminiscent of Angular's Reactive form validation.
Related
I am new in Laravel I want to need some validation if I checked checkbox then in front of input field will validate Required|Numeric|min:1
Please Help.
As per below image
You are looking for required_if.
So, you could have the following rules in your Form Request or your Validator.
return [
'systolic_blood_pressure_high' => 'nullable|numeric|min:1|required_if:has_systolic_bp,on',
'systolic_blood_pressure_low' => 'nullable|numeric|min:1|required_if:has_systolic_bp,on',
];
Assuming you have a checkbox with name has_systolic_bp and it is checked, the fields systolic_blood_pressure_high and systolic_blood_pressure_low will be required.
You also need to mark them as nullable as by default Laravel will consider them as invalid because of the TrimStrings and ConvertEmptyStringsToNull middlewares.
For more information, check the documentation
I'm using Swagger documentation with my flask project to document the endpoints and parameters.
To define the query parameters for an endpoint I'm doing:
#api.doc(params={
'name_query_parameter': 'Description'})
I wanted to know if it's possible for that parameter to show in the docs as "required", like it does for when the parameter is part of the path (home/name_query_parameter/something/something).
Looking into the documentation I only found the following:
#api.expect()
#api.doc(body=the_defined_payload)
But this implies for the information to be on the body, I can't have that with a GET request. Plus, I want it as a query parameter, not as part of the payload.
Is this possible at all?
Thanks.
The final solution to this is as follows, thanks to Mikhail for commenting about the parser. I have to admit though, documentation is not the best for flask-restplus.
I used the params part to make sure the fields appear in the docs along with a description and the parser for custom validation and to make the field appear as required even though it is located in the URL as params.
parser = reqparse.RequestParser()
parser.add_argument('superimportant',
type=inputs.boolean, location='args', required=True)
parser.add_argument('something', type=custom_validation_parser, location='args')
class MySuperClassResource(Resource):
#api.doc(parser=categories_by_retailer_parser,
params={"superimportant": "Description of this important field",
"something": "bla bla"
})
def get(self, blable):
parser.parse_args()
pass
The custom_validation_parser is just a method that allows custom validation, like for empty values. The format of that method is as follows. (It must return the value you want to access, and if there's . problem, raise a ValueError).
def custom_validation_parser(value):
if not value:
raise ValueError("Must not be empty.")
return value
When I don't provide any of the translatable properties through my submit form, then I get no validation checking, even when I have implemented:
/**
* #Assert\Valid
*/
protected $translations;
In config.yml I have:
default_locale: cs
required_locales: [cs]
All topics about this problem were giving importance on the #Assert/Valid on $translations property, which I have implemented (I have even tried validation.yml configuration).
Now I realise, that I forgot to add, that I am displaying and submiting the form through Easy Admin bundle. I am not building the form myself. Just configuring Easy Admin settings for my entity. Maybe there's some glitch.
Please refer the following answer link related to same question:
Collection array name fields validation:
A2Lix form validation for translations field
try adding required option to your easy admin type settings
- { property: 'translations', type: 'a2lix_translations', type_options: { required: true} }
My routes have something like this
return this.store.query('author', {filter:{username : username},
include: 'books, books.readers'})
as we can see author has Many-2-Many relationships with books, book have relationship with reader
How can I include books.reader when run query with author?
Ember Data provides the ability to query for records that meet certain criteria. Calling store.query() will make a GET request with the passed object serialized as query params. This method returns a DS.PromiseArray in the same way as findAll.
So for example in your case author with :username can be changed to the following code:
// GET to /persons?filter[username]=username
this.get('store').query('author', {
filter: {
username: username
}
}).then(function(username) {
// Do something with `username` which can be another filter and whatever else you want, give it a try.
});
Hope it can solve your problem.
I have just started learning cfwheels. I was working on the sample "Social Networking Site" example present in the site(http://cfwheels.org/screencasts/series/1).
I have a doubt. We have register.cfm and login.cfm two views present. Both the veiws are using the user object
created from Person.cfc(modal).
All the validations that are required in the registration form , we have written inside Person.cfc init() method. Now on the login.cfm
we have two fields named Email and password and I want to validate the email to be in correct format in server side before checking
for valid Email/Password combination.
Now where should I write this validation code for login.cfm?
The server side validation should be done on the action inside the Controller.
For example if you are submitting the form to doLogin action of the Authentication controller/component, the validation code should go inside the doLogin() function of the same controller.