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...
Serverside validation as the option is selected from the list of options provided and not somehow injected
A message stating 'Invalid field: «field name»'.
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.
Possibly server-side validation is not possible for custom list fields, but this is not very clear.
Labels |
Added:
No Code Attached Yet
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-11-13 10:33:17 |
Closed_By | ⇒ | joomdonation |
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 foroptions
property. See https://github.com/joomla/joomla-cms/blob/4.2-dev/libraries/src/Form/Field/ListField.php#L227-L234 for an exampleThat 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.