-
-
Notifications
You must be signed in to change notification settings - Fork 174
JsValidator Reference
A Proengsoft\JsValidation\JsValidator
instance is returned by the Facade methods.
The mainly use of this object is to provide the converted rules and messages to the view, for propper rendering of Javascript code.
To customize the view refer to Javascript Rendering and JQuery Validation Plugin documentation.
public function selector()
public function view()
public function render()
Arrayable interface
public function __toString()
Specifies the jQuery selector to define the form to validate
-
$selector
(string|null) JQuery Selector used to select the form to be validated. Optional, selector defined in Configuration will be used by default.
-
JsValidator
. instance to be rendered.
Controller
$validator = JsValidator::make(['name' => 'required|min:5']);
// ...
return view('my-form-view', ['validator'=>$validator]);
View
<form>
<input name="name" />
</form>
{!! $validator->selector('#my-morm-id') !!}
Render the specified view with validator data
-
$view
(lluminate\Contracts\View\View|string|null) View used to render the Javascript initialization code. Optional, view definned in Configuration will be used by default. -
$selector
(string|null) JQuery Selector used to select the form to be validated. Optional, selector defined in Configuration will be used by default.
-
string
. the html and Javascript code to initialize the validators.
Controller
$validator = JsValidator::make(['name' => 'required|min:5']);
// ...
return view('my-form-view', ['validator'=>$validator]);
View
<form>
<input name="name" />
</form>
{!! $validator->render('my-custom-javascript-view', '#my-morm-id') !!}
This class implements Illuminate\Contracts\Support\Arrayable interface tho provide validation data to view. This keys are provided:
-
selector
JQuery selector to find the form to validate. -
rules
JQuery Validation Plugin rules to validate the form -
messages
Messages displayed when validation fails.
When this class is converted to string is called render
method with default view and selector
public function __toString()
{
return $this->render();
}