Admin Field Relations JFormRuleInt has invalid regex error #446

Closed
opened 2019-07-18 11:05:26 +00:00 by TLWebdesign · 4 comments
TLWebdesign commented 2019-07-18 11:05:26 +00:00 (Migrated from github.com)

Steps to reproduce the issue

Create a admin field relation

Expected result

admin field creation succesful created.

Actual result

Error: JFormRuleInt has invalid regex

Schermafbeelding 2019-07-18 om 13 02 33

System information (as much as possible)

  • OS Name & Version: MacOS latest
  • Joomla Version: 3.9.10
  • JCB Version: 2.9.21
  • Browser: Firefox latest

Additional comments

### Steps to reproduce the issue Create a admin field relation ### Expected result admin field creation succesful created. ### Actual result Error: JFormRuleInt has invalid regex ![Schermafbeelding 2019-07-18 om 13 02 33](https://user-images.githubusercontent.com/4402824/61452711-b3321500-a95c-11e9-94c5-bf7208b10c7f.png) ### System information (as much as possible) - OS Name & Version: MacOS latest - Joomla Version: 3.9.10 - JCB Version: 2.9.21 - Browser: Firefox latest ### Additional comments
TLWebdesign commented 2019-07-18 11:07:31 +00:00 (Migrated from github.com)

Seems like an older version of JCB on 3.9.10 gives same error.

Seems like an older version of JCB on 3.9.10 gives same error.

Some times things break when other things get fixed... thanks for the heads-up I am on it.

Some times things break when other things get fixed... thanks for the heads-up I am on it.

Well at this point I am suspicious that this is a Joomla bug... but I will look a little more. Those who can follow... the error comes from here: line 71 in /libraries/src/Form/FormRule.php because of this: line 158 and 176 of /admin/models/forms/admin_fields_relations.xml

So to do a work around for now... just remove the validate="int" lines from the xml and it should work.

TO fully fix this I need to look a little more 👍

Well at this point I am suspicious that this is a Joomla bug... but I will look a little more. Those who can follow... the error comes from here: [line 71 in /libraries/src/Form/FormRule.php](https://github.com/joomla/joomla-cms/blob/3.9.10/libraries/src/Form/FormRule.php#L71) because of this: [line 158](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/models/forms/admin_fields_relations.xml#L158) and [176]( https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/models/forms/admin_fields_relations.xml#L176) of /admin/models/forms/admin_fields_relations.xml So to do a work around for now... just remove the `validate="int"` lines from the xml and it should work. TO fully fix this I need to look a little more :+1:

Ahhh found it... the int validation is not a Joomla class, but a custom JCB class, and it worked before, but not anymore... so I just added it in and will be in the next release. For now add the following code:

So in /admin/models/rules/int.php add the following method:

	/**
	 * Method to test that an integer value was added.
	 *
	 * @param   \SimpleXMLElement  $element  The SimpleXMLElement object representing the `<field>` tag for the form field object.
	 * @param   mixed              $value    The form field value to validate.
	 * @param   string             $group    The field name group control value. This acts as an array container for the field.
	 *                                       For example if the field has name="foo" and the group value is set to "bar" then the
	 *                                       full field name would end up being "bar[foo]".
	 * @param   Registry           $input    An optional Registry object with the entire data set to validate against the entire form.
	 * @param   Form               $form     The form object for which the field is being tested.
	 *
	 * @return  boolean  True if the value is valid integer, false otherwise.
	 *
	 */
	public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
	{
		// Check if the field is required.
		$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');

		// If the value is empty and the field is not required return True.
		if (($value === '' || $value === null) && ! $required)
		{
			return true;
		}

		// now validate the value to be an integer
		// we need to validate a string with the integer in it
		// since this is how Joomla passes the value to the test method
		// so we use type coercion along with is_numeric
		return is_numeric($value) && is_int(+$value);
		// if you have a better idea... lets hear it.
	}

This should resolve the issue.

Ahhh found it... the int validation is not a Joomla class, but a custom JCB class, and it worked before, but not anymore... so I just added it in and will be in the next release. For now add the following code: So in [/admin/models/rules/int.php](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/models/rules/int.php) add the following method: ```php /** * Method to test that an integer value was added. * * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param Registry $input An optional Registry object with the entire data set to validate against the entire form. * @param Form $form The form object for which the field is being tested. * * @return boolean True if the value is valid integer, false otherwise. * */ public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) { // Check if the field is required. $required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required'); // If the value is empty and the field is not required return True. if (($value === '' || $value === null) && ! $required) { return true; } // now validate the value to be an integer // we need to validate a string with the integer in it // since this is how Joomla passes the value to the test method // so we use type coercion along with is_numeric return is_numeric($value) && is_int(+$value); // if you have a better idea... lets hear it. } ``` This should resolve the issue.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#446
No description provided.