AnsweredAssumed Answered

How can I validate fields in Accounts when creating new records?

Question asked by Maria Georgieva on Mar 24, 2014
Latest reply on Oct 8, 2014 by Cheth Cheth
I found some working example of how to add validation to the record.js that executes after the Save button is hit. However, it was later discovered, this validation was not working when first creating a new record (module is Accounts).
I tried including the slightly modified code to custom/modules/Accounts/clients/base/views/create/create.js but it seems like the action is not invoked?
What is the right action to extend when creating an Account record? Anything I'm doing wrong?

({    extendsFrom: 'CreateView',
    initialize: function (options) {
  console.log('Initializing Create View'); //trying to see if action is invoked
        app.view.invokeParent(this, {type: 'view', name: 'create', method: 'initialize', args:[options]});

        //add validation
        this.model.addValidationTask('check_fieldname', _.bind(this._doValidateCheckFieldName, this));

    _doValidateCheckFieldName: function(fields, errors, callback) {
        //validate requirements
  var msg = '';
  var count_errors = 0;
  var field_val = this.model.get('field_c');
  /* Validation check goes here */
        if (count_errors != 0)
            errors['field_c'] = msg;
            errors['field_c'].required = true;
        callback(null, fields, errors);