I am new to this fantastic October after 10 years of Joomla and would like to continue on it. I'm using the great Builder plugin and would like to have 'complex' validations in back-end with 'create' or 'update' forms.
After many time browsing the net, I can't figure how to and where to put code to add business validation rules ?
I played with yaml options to have dynamic fields and simple validations. Now I would like to have complex rules, like : if a category is X and a type is Y then the (text) name field is SET to 'ZZZ' Could somebody put me on the way to add such code in PHP ?
I'm able to read field values, but I can't change the inputs programmatically. After many tries, I'm stuck on the problem. Any help would be greatly appreciated. Thanks.
[EDIT] After Raja help, I modified my code like this : PHP Model
class Event extends Model {
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
public $rules = [];
// in models/your_object_model
public function filterFields($fields, $context = null) {
echo "\r\n".'filterFields() : '.$this->nom."\r\n";
// var_dump($fields->nom);
if ( $this->nom == 'toto' ) {
echo $this->nom.' is french'."\r\n";
$fields->pays->value = 'FR';
$fields->pays->hidden = true;
$fields->ville->value = 'Paris';
}
}
}
YAML :
fields:
nom:
label: Nom
span: full
type: text
description:
label: Description
size: ''
span: full
type: richeditor
pays:
label: Pays
span: auto
default: US
type: text
dependsOn: nom
ville:
label: Ville
span: auto
default: NY
dependsOn: nom
type: text
What I understood is that filterFields() is fired based on the YAML dependsOn: nom.
When I fill 'Nom' and click in Description, the result is now :
1) I'm still unable to change a value in the form as I go in the function, because I display the string "toto is french"
2) On the text fields I try to modify, I get and endless spinner and the fields now can't be entered with mouse, only with keyboard
3) How could I remove the green string X_OCTOBER_ASSETS ?