This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello,
I`m extending plugin with custom fields
Add validation, but always get validation error message,
I was trying 2 methods(commented) but without success.
public function boot()
{
RealtyModel::extend(function ($model) {
$model->hasOne['addproperties'] = ['Eduard\AddProperties\Models\AddProperties'];
$model->rules = ['floor' => 'required'];
// $model->bindEvent('model.beforeCreate', function () use ($model) {
// $model->rules = ['floor' => 'required'];
// });
});
I have in my class
class Plugin extends PluginBase
{
use \October\Rain\Database\Traits\Validation;
Is there other decision?
Thanks
I have...
class Realty extends Model
{
use \October\Rain\Database\Traits\Validation;
It works properly only for original fields, but not for extended
It looks like validator do not receive data from input field and alway stay not valid
In my Plugin.php of my extended plugin
class Plugin extends PluginBase
{
use \October\Rain\Database\Traits\Validation;
....
public function boot()
{
RealtyModel::extend(function ($model) {
$model->hasOne['addproperties'] = ['Eduard\AddProperties\Models\AddProperties'];
$model->rules = ['floor' => 'required'];
// $model->bindEvent('model.beforeCreate', function () use ($model) {
// $model->rules = ['floor' => 'required'];
// });
});
Last updated
I take it from
https://octobercms.com/docs/database/traits#validation
What should I add?
O sorry don`t catch what you mean
public function boot()
{
RealtyModel::extend(function ($model) {
$model->hasOne['addproperties'] = ['Eduard\AddProperties\Models\AddProperties'];
$model->rules = ['floor' => 'required'];
// $model->bindEvent('model.beforeCreate', function () use ($model) {
// $model->rules = ['floor' => 'required'];
// });
});
RealtyControllers::extendListColumns(function ($list, $model) {
if (!$model instanceof RealtyModel) {
return;
}
$list->addColumns([
'building' => [
'label' => 'Building',
],
]);
});
RealtyControllers::extendFormFields(function ($form, $model, $context) {
if (!$model instanceof RealtyModel) {
return;
}
if (!$model->exists) {
return;
}
AddPropertiesModel::getFromRealty($model);
$form->addTabFields([
'addproperties[floor]' => [
'label' => 'Floor',
'tab' => 'Standart Property',
'type' => 'number',
'span' => 'storm',
'cssClass' => 'col-xs-2',
'required' => true,
],
//cut some fields...
]);
});
}
You're adding a validation rule for a field that has not been defined... unless it's already in the Model you're extending?
Ok, how should I define this fields in the Model?
Please give me an example or link
I have no idea from the docs...
I found this
$model->addFillable(['floor']);
but it doesn't help
mjauvin could you please give me advise
As Luke Towers pointed out on Slack, you are defining the validation rules in the wrong model...
Since floor is a property of the AddProperties Model, that's where you need to set the rule.
1-15 of 15