Updated 045 Adding your own rule validation to a field in JCB (markdown)

Amigo 2019-08-24 16:26:44 +02:00
parent 331fd9b9aa
commit e01f2d0cba

@ -3,13 +3,18 @@
[00:00:00](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m00s)
(_Click on these time links to see Youtube video_)
I would like to demonstrate how to add rules to the Model, basically to a Field. The custom rules are used to test a value before submitting it to the database. This is quite a good feature to have in your Component. [00:00:32](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m32s) For this demonstration the Hello World Component are going to be used and rule is going to be added to one of its Fields. Open Greeting (first) as the Admin View. To change the Field in it this(See video) 'Greetings' are used. [00:01:11](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m11s) The Field attributes do not have the validation option switch in place. We might start shipping JCB with this new validation property which is not new, it has just not being added yet. If you have a version of JCB that does not have it set, then whatever Fieldtype which is selected and can be edited by going to the green button, or you could edit the Fieldtype by going to Fieldtypes. [00:01:47](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m47s) Close out of Edit the Admin View again then go to Fieldtypes in Admin View. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
I would like to demonstrate how to add rules to the Model, basically to a Field. The custom rules are used to test a value before submitting it to the database. This is quite a good feature to have in your Component. [00:00:32](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m32s) For this demonstration the Hello World Component is going to be used and a rule is going to be added to one of its Fields. Open Greeting (first) as the Admin View. To change the Field in it this(See video) 'Greetings' are used. [00:01:11](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m11s) The Field attributes do not have the validation option switch in place. We might start shipping JCB with this new validation property which is not new, it has just not been added yet. If you have a version of JCB that does not have it set, then whatever Fieldtype which is selected and can be edited by going to the green button, or you could edit the Fieldtype by going to Fieldtypes. [00:01:47](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m47s) Close out of Edit the Admin View again then go to Fieldtypes in Admin View.
### Select Fieldtype To Add Validation - Textarea
[00:01:55](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m55s)
You can select the Fieldtype that you want to add this validation to. We want to do it for now to the Textarea. It has a filter in place. I'm going to add validation just underneath it. I'm going to click a plus. It is adjustable, it's not required, it's not translatable. Let's give it a little [00:02:22](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m22s) description. We got it all set. I wouldn't add a value here because if you don't want to use it, you just leave it empty. Let's save and close. We've done the Textarea. Let's go back to our Admin View Greetings and again open that Greetings(Textarea) field. Now we have this validate property available to us. We can copy it and add it in XML field definition.
A Fieldtype may be selected to add this validation too, for example, the Textarea. It has a filter in place. A validation is added just below it. Click a plus. It is 'adjustable', it is not 'required' and it is not 'translatable'. Then give it a little description. [00:02:22](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m22s) We got it all set. A value would not be added because if you do not want to use it, leave it empty. Save and close. With the Textarea been done, go back to the Admin View Greetings and again open that Greetings(Textarea) field. Now, this 'validate' property is available to us and can be copied and added in XML field definition. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
### Custom Validation Rule