Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Model conditional validations

  1. #11
    Sencha Premium Member
    Join Date
    Jul 2014
    Posts
    70
    Answers
    1

    Default my workaround

    This is what I did. I extended Model and added these methods:

    isValid: function () {
    if (this.skipValidation()) {
    return true;
    }
    return this.callParent(arguments);
    },
    // this can be overridden in a sub class if the class should skip validation
    skipValidation: function () {
    return false;
    }

    then I override skipValidation using conditions based on the record.

  2. #12

    Default

    What I ended up doing was use the 'validator' configuration of the textfield, get the model instance from my viewmodel, and call a custom validate method added to the model.Cleanest way I could think of. Too bad it pollutes the view class with code logic.

  3. #13
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    40
    Answers
    2

    Default

    @lrayman is right, I've got a new ugly workaround:


    Ext.define('Overrides.app.bind.Stub', {
    override: 'Ext.app.bind.Stub',

    bindValidationField: function (callback, scope) {
    var parent = this.parent,
    name = this.name,
    lateBound = typeof callback === 'string',
    ret;

    if (parent) {
    ret = parent.bind(function (value) {
    var field = null;

    if (value && value.isModel) {
    field = value.getField(name);
    field.record = value;
    }
    if (lateBound) {
    scope[callback](field, null, this);
    } else {
    callback.call(scope, field, null, this);
    }
    });
    }

    return ret || null;
    }
    });

  4. #14
    Sencha Premium User lumberjack's Avatar
    Join Date
    Nov 2014
    Location
    Kansas
    Posts
    781
    Answers
    102

    Default

    Here's an approach without using any overrides. I use a calculated field that returns an object containing all of my dependency field names and their values.


  5. #15

    Default

    Excelent ideea @lumberjack !A more cleaner workaround, and with this I could create a common validator instead of duplicating code.Thanks!

  6. #16

    Default

    Actually @lumberjack this doesn't allow you to bind the field you are trying to validate to a form (e.g. in the case of a password confirmation field)It's so annoying.. this wouldn't be a problem if the validator would actually work like it's doccumented, and would be passed the model to the validate function.http://docs.sencha.com/extjs/5.1/5.1...ethod-validate

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •