No Code Attached Yet
avatar stephan-ansems
stephan-ansems
26 May 2022

Steps to reproduce the issue

Create a custom field «component»\src\Field\DatacenterField.php which loads has a helper method to get the options values from the database. Then create a form where the fueld is declared like this:

<field
  name="datacenters"
  type="supplierDatacenter"
  label="Main datacenter"
  validate="options"
  default="FR"
/>

Click 'save' and get an error...

Expected result

Serverside validation as the option is selected from the list of options provided and not somehow injected

Actual result

A message stating 'Invalid field: «field name»'.

System information (as much as possible)

The issue is somewhere in the OptionsRule.php as this is the rule supposed to validate the input. It seems the OptionsRule looks at the xml definition of the field, but this lacks the valid options.

Additional comments

Possibly server-side validation is not possible for custom list fields, but this is not very clear.

avatar stephan-ansems stephan-ansems - open - 26 May 2022
avatar joomla-cms-bot joomla-cms-bot - change - 26 May 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 26 May 2022
avatar joomdonation
joomdonation - comment - 13 Nov 2022

Base on what I see from the code of OptionsRule, it will be possible. The easiest way would be your own custom field class has a implement magic __get method which return available options for options property. See https://github.com/joomla/joomla-cms/blob/4.2-dev/libraries/src/Form/Field/ListField.php#L227-L234 for an example

That method would need to return list of options available for your field so that Joomla can validate the submitted data.

As this is not an issue with Joomla but it is your own field type implementation, I'm moving this issue to discussion so that we can discuss further from there if needed.

avatar joomdonation joomdonation - change - 13 Nov 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-11-13 10:33:17
Closed_By joomdonation
avatar joomdonation joomdonation - close - 13 Nov 2022

Add a Comment

Login with GitHub to post a comment