protectedfunctionrules():array{returnarray_merge($this->fieldRules(), [ //your custom rules here ] );}
Override auto generated field validation attributes
protectedfunctionvalidationAttributes():array{returnarray_merge($this->fieldValidationAttributes(), [ //your custom field validation attributes here ] );}
Form validation settings
// config/tall-forms'form'=> ['labelsAsAttributes'=>true,//use field labels as validation :attribute'notifyErrors'=>true,//display notification errors as popups, not just text]// override in componentprotectedfunctionformAttr():array{return ['labelsAsAttributes'=>true,'notifyErrors'=>true, ]}
Field validation methods
Fields are automatically validated when the form is submitted. (If you extend the TALL-form component.)
errorMsg(string $string)//custom validation messagekeyAsAttribute()//use the field key as validation :attribute, overrides $form->labelsAsAttributesvalidationAttr()//Set a custom validation :attributerules(mixed $rules)//defaults to 'nullable', Use any Laravel rule
Field real-time validation methods
You can disable/enable automatic real-time validation with different field methods, depending on the field type. Defaults are set in config/tall-forms field-attributes
deferEntangle(true)//realtime validation offdeferEntangle(false)//realtime validation onwire('lazy')//realtime validation on, validates when the field looses focuswire('defer')//update field value on next request, realtime validation offrealtimeValidationOff()//consider using wire('defer) instead
Examples
Validation rules precedence
classFooFormextendsTallFormComponent{//rules() takes precedenceprotectedfunctionrules():array {return ['email'=> ['required','email','not_in:'.auth()->user()->email], ]; }//overridden by rules() methodprotectedarray $rules = ['email'=>'nullable', ];//overridden by both rules() and $rules protectedfunctionfields():array {return [Email::make('Email')->rules('required|string'); ]; }//real-time validation hook where you can override all other defined rulesprotectedfunctionupdatedEmailValidate($value) {//you need to call $this->validateOnly(...) manually here.//see Livewire documentation https://laravel-livewire.com/docs/2.x/input-validation }}
Component $rules combined with field->rules(), example
Some fields of array type apply field rules to each item in the array. If you want a rule that applies to the array instance you have to add it manually using Livewire default $rules property or rules() method.
protectedarray $rules = ['topics'=>'required|array|min:1',];protectedfunctionfields(){return [InputArray::make('Topics')->type('text')->minItems(1)->help('Please list at least one topic')->rules('required|string|between:3,5'); //the rules are applied to each input field ];}