Updated 045 Adding your own rule validation to a field in JCB (markdown)
parent
2b9ad88ca3
commit
567c9856ab
@ -32,21 +32,23 @@ First, create a rule. This rule 'JFormRule' is added. In the folder structure, i
|
|||||||
|
|
||||||
[00:06:38](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m38s)
|
[00:06:38](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m38s)
|
||||||
|
|
||||||
In the back end of the component, go to models, forms, and this greeting form is targeted. It has '/models/rules'. Copy that. Remember that it is the Admin area and then '/models/rules'. [00:07:07](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m07s) This Admin is the way the package is build. The target place should be the place inside the package. This is always the case for both Folders and Fields. In the Folder you want it to add it to the Admin models rules folder. Then you need to decide whether you want this file to be updated. At this stage that files does not need any updating.<<<<<<<<
|
In the back end of the component, go to models, forms, and this greeting form is targeted. It has '/models/rules'. Copy that. Remember that it is the Admin area and then '/models/rules'. [00:07:07](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m07s) This Admin is the way the package is build. The target place should be the place inside the package. This is always the case for both Folders and Fields. In the Folder you want it to add it to the Admin models rules folder. Then you need to decide whether you want this file to be updated. At this stage that files does not need any updating.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Adding A License Tag
|
### Adding A License Tag
|
||||||
|
|
||||||
[00:07:34](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m34s)
|
[00:07:34](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m34s)
|
||||||
|
|
||||||
But we can change that. You can see I've just added this new licence tag to it(see video). And I've added this ###BOM###. When the file gets taken it will take this part away and replace this with your components licence and so the file will become branded like every other file in your component. [00:08:06](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m06s) Even if you use it in areas or components other than the one you originally made it for, it will dynamically looked like it was made for it because it add that components data at the header of the file. Even if you had the components name somewhere else in this, you can replace it with the well-known ###component### and it will be placed with the component name. We've got our file in place. You wanted to be updated. Let's compile the component and see it in action. In 'A New Component Files & Folders' just tick this as yes that the file should be updated. [00:08:54](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m54s) Then save and close. Close out of the Component again. There's a shortcut to that file area underneath hello_world that you can use. We go to the Compiler and we compile our component. Let's install our Component. Now let's go look at the code to see what happened. In our components admin area, if we open the rules, we see there is the file 'strlenTen', it was placed into rules folder. If we open 'strlenTen' file we see [00:09:39](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m39s) it added our copy notice to the header of the file. Let's also look at our greeting.xml. We see the validation is there strlen.Ten so Everything so far so good.
|
But we can change that. This new licence tag has just been added to it(see video) as well as this ###BOM###. When the file gets taken, it will take this part away and replace this with your components licence and so the file will become branded like every other file in your component. [00:08:06](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m06s) Even if you use it in areas or components other than the one you originally made it for, it will dynamically look like it was made for it because it add that components data at the header of the file. Even if you had the components name somewhere else in this, you can replace it with the well-known ###component### and it will be placed with the component name. With our file in place, we want it to be updated. Compile the component and see it in action. In 'A New Component Files & Folders' just tick this as 'Yes', that the file should be updated. [00:08:54](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m54s) Then save and close. Close out of the Component again. There is a shortcut to that file area below 'hello_world'. Then go to the Compiler and compile the component. Install the Component. Go look at the code to see what happened. In the components Admin area, if rules are opened, there is the file 'strlenTen', it was placed into rules folder. If we open 'strlenTen' file, it may be seen that it added our copy notice to the header of the file. Also look at our greeting.xml. The validation is 'strlen.Ten'.
|
||||||
|
|
||||||
### Testing The Validation
|
### Testing The Validation
|
||||||
|
|
||||||
[00:10:02](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m02s)
|
[00:10:02](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m02s)
|
||||||
|
|
||||||
Now let's go test this. We open the component in the back end. We go to Greetings. We click New. As you remember we set that Greetings needs to have a length of at least 10 characters. Let's test this. We add Greeting which isn't enough and we click Save. It tells us Invalid Field: Greetings. Problem. [00:10:36](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m36s) There's one little change I had to make to get this to work and I realize I'll need to tell you. Let's go look at this for some reason they want this file all lowercase. II had to change strlen.Ten to the T also in lowercase. Let's go do this also with the file in our custom folder. Then inside of the actual file they also want the T here to be lowercase. I suppose because they are using the upper case camel rule to sort of break-up the name. That was what I had to do to get it to work. [00:11:20](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m20s) I also need to update the component to include this file since the name is changed, it will no longer know where it is. We can go directly to that file area with thhowe shortcut underneath hello_world and we see it is no longer selected, so we scroll down, select it again and save and close. Now that we've fixed the little glitch which I created myself, let's go back to see this again in action. [00:11:57](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m57s) And save. And Invalid field: Greetings. That isn't very helpful. Maybe you would like to also show a custom message so that the user would at least know more about what is going on here. Before we do that let's add enough values and see if that it actually saves. It's saved successfully. Close. Our Greetings is been saved and our value here(Greetings) is more than 10 characters, so it was valid.
|
Now let us test this. Open the component in the back end, go to 'Greetings' and click 'New'. 'Greetings' had been set to have a length of at least 10 characters. Let's test this. 'Greeting' is added which does not have enough characters and click 'Save'. It tells us, 'WARNING: Invalid Field: Greetings'. [00:10:36](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m36s) One little change is necessary to get this to work. For some reason they want this file all lowercase. The 'T' uppercase in 'strlen.Ten' need to change to 'T' lowercase. Do this also with the file in our Custom folder. Then in the actual file the 'T' should be lowercase. Perhaps the upper case camel rule is used to sort of break-up the name.<<<<
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
That was what I had to do to get it to work. [00:11:20](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m20s) I also need to update the component to include this file since the name is changed, it will no longer know where it is. We can go directly to that file area with thhowe shortcut underneath hello_world and we see it is no longer selected, so we scroll down, select it again and save and close. Now that we've fixed the little glitch which I created myself, let's go back to see this again in action. [00:11:57](https://www.youtube.com/watch?v=Z6-ggKtX35o&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m57s) And save. And Invalid field: Greetings. That isn't very helpful. Maybe you would like to also show a custom message so that the user would at least know more about what is going on here. Before we do that let's add enough values and see if that it actually saves. It's saved successfully. Close. Our Greetings is been saved and our value here(Greetings) is more than 10 characters, so it was valid.
|
||||||
|
|
||||||
### Add A Custom Messages To Validation
|
### Add A Custom Messages To Validation
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user