1

From this incredibly helpful validation article(s), I found that:

AttributeType::Mixed does not apply any validation rules

Ok cool. I am using two fields that are DateTime fields, but due to a known bug, a work-around is to make the field type Mixed.

Everything is working 100% - and I can't thank the community for their help.

However, in my settings page, I would (like) to have my start date (Mixed) and end date (Mixed) fields required.

This isn't a make-or-break deal, just curious if there is a way.

MyPlugin.php

....
'myStartDate' => array(AttributeType::Mixed, 'required' => true),
'myEndDate' => array(AttributeType::Mixed, 'required' => true),
....

EDIT

Hi Brad, they are attribute settings. I've updated to show the file(s) below. Thank you for your time!

_settings.html

....
{{
    forms.dateField({
        'label': "Start Date"|t,
        'instructions': "What week do we start?"|t,
        'required': true,
        'id': 'myStartDate',
        'name': 'myStartDate',
        'placeholder': 'mm/dd/yyyy',
        'value': settings.myStartDate,
        'errors': settings.getErrors('myStartDate')
    })
}}
....

MyPlugin.php

public function defineSettings()
{
    return array('myStartDate' => array(AttributeType::Mixed, 'required' => true),
                 'myEndDate' => array(AttributeType::Mixed, 'required' => true)
        );
}

If I make the field type a DateTime, then the required works. Maybe it's all part of the same bug. If it is, that's cool. It's not a big deal I'm more curious if I'm doing something wrong for the field type since ::Mixed does not apply any validation rules.

  • Are those settings attributes or proper model attributes? – Brad Bell Apr 13 '15 at 2:28
1

100% untested and I haven't had coffee yet, but I think it'd be a combination of a few things.

1) Having your plugin override BaseSavableComponentType's getSettingsModel() so that it returned a MyPluginSettingsModel().

2) Have MyPluginSettingsModel override the rules method to do something like:

public function rules()
{
    $rules = parent::rules();

    $rules[] = array('myStartDate, myEndDate', 'required');

    return $rules;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.