Archived talk

Difference between revisions of "Developing a MVC Component/Adding verifications"

From Joomla! Documentation

(→‎Attention: new section)
 
(13 intermediate revisions by 5 users not shown)
Line 4: Line 4:
  
 
Section about admin/views/helloworld/tmpl/edit.php is not the same as in file present in archive.
 
Section about admin/views/helloworld/tmpl/edit.php is not the same as in file present in archive.
 +
 +
== verification seems to operate even when required="false" is coded  ==
 +
 +
I have expanded the helloworld component to have several other fields now, and set some of them to required="false" in the /models/forms/app.xml file. I still get "invalid field" when I leave the input box empty. Any ideas?
 +
 +
(later) I think I figured it out: the client-side script operates on every field it's assigned to, whereas the server-side <i>may</i> operate only on a field that's required and not empty. Not sure about that last, but I am sure that the client-side script operates, so you may want to code the regex differently in admin/models/forms/<com-name>.js (the client side) vs admin/models/rules/<field>.php .
 +
 +
[[User:IslandBilly|&quot;In theory, there&#39;s no difference between theory and practice; in practice, there is&quot;  --Yogi Berra]] 10:51, 30 September 2011 (CDT)
 +
 +
== Minor misstatement ==
 +
 +
After editing admin/views/helloworld/view.html.php, where the tutorial reads:
 +
 +
<strong>This view now</strong>
 +
<ul>
 +
    <li>verifies if the model has no error;</li>
 +
    <li><em><strong>adds two javascript files;</strong></em></li>
 +
    <li>injects javascript translation using the Joomla JText::script function. </li>
 +
</ul>
 +
 +
I believe the statement &quot;adds two javascript files;&quot;, is incorrect. One javascript file has been added (submitbutton.js), and the second javascript file is added in the next step in the getScript function, (helloworld.js).
 +
 +
Am I correct on this? If so, I can see where sometimes one might want to use both methods to add scripts, but it seems to only be for demonstration purposes here since it seems both scripts could be added by either method.
 +
 +
== Additional discussion about server-side validation would be helpful. ==
 +
 +
Additional discussion about server-side validation would be helpful. Why does simply declaring the $regex variable create a validation rule? There does not appear to be any rule logic or class method applied to the field value.
 +
 +
I'm also not sure about the function of the javascript language translation
 +
 +
<blockquote>alert(Joomla.JText._('COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE','Some values are unacceptable'));</blockquote>
 +
 +
since it does not seem to work unless COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE is in the translation file. Additional explanation on this would be helpful.

Latest revision as of 17:18, 26 April 2022

Why is the protected function _populateState() in the /admin/models/helloworld.php file? It doesn't appear in the original helloworld.php model file, and there isn't any indication as to the purpose of this function aside from the annotations within the function, which I don't fully understand.

Attention[edit]

Section about admin/views/helloworld/tmpl/edit.php is not the same as in file present in archive.

verification seems to operate even when required="false" is coded[edit]

I have expanded the helloworld component to have several other fields now, and set some of them to required="false" in the /models/forms/app.xml file. I still get "invalid field" when I leave the input box empty. Any ideas?

(later) I think I figured it out: the client-side script operates on every field it's assigned to, whereas the server-side may operate only on a field that's required and not empty. Not sure about that last, but I am sure that the client-side script operates, so you may want to code the regex differently in admin/models/forms/<com-name>.js (the client side) vs admin/models/rules/<field>.php .

"In theory, there's no difference between theory and practice; in practice, there is" --Yogi Berra 10:51, 30 September 2011 (CDT)

Minor misstatement[edit]

After editing admin/views/helloworld/view.html.php, where the tutorial reads:

This view now

  • verifies if the model has no error;
  • adds two javascript files;
  • injects javascript translation using the Joomla JText::script function.

I believe the statement "adds two javascript files;", is incorrect. One javascript file has been added (submitbutton.js), and the second javascript file is added in the next step in the getScript function, (helloworld.js).

Am I correct on this? If so, I can see where sometimes one might want to use both methods to add scripts, but it seems to only be for demonstration purposes here since it seems both scripts could be added by either method.

Additional discussion about server-side validation would be helpful.[edit]

Additional discussion about server-side validation would be helpful. Why does simply declaring the $regex variable create a validation rule? There does not appear to be any rule logic or class method applied to the field value.

I'm also not sure about the function of the javascript language translation

alert(Joomla.JText._('COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE','Some values are unacceptable'));

since it does not seem to work unless COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE is in the translation file. Additional explanation on this would be helpful.