0

Say I have a custom angular-formly type that extends a input type. Lets call it user.

Before the form gets filled in model = {}.

Once its filled in and valid, I would like to have this result

model = {
    user:{
        name:"TestName" //The value of the input
        someCustomData: "Not part of the form"
        someMoreMetaData: "Also not part of the from"
    }
}

The resulting model having appended arbitrary meta-data once user entered a valid name. Thus creating a "user specific model"

So basically, I want my validation function to push the result to the model.

How would I approach this, for the key has to be bound to a property of a object that will only exist once validation returns true.

{
    key: //what do I bind to?
    type: 'USER',
    templateOptions: {
        required: true,
        type: 'text'
    },
    validators:{
        isValid: function($viewValue, $modelValue, scope){
           var value = $modelValue || $viewValue;
           if (validateName(value)){
              scope.model.user = { name: viewValue, date:....}
              return true;
           }
        }
    }

}

If possible, please nudge me in the right direction..Still pretty novice.

1
  • Can you share some code, what do you currently have? Commented Nov 30, 2015 at 10:54

2 Answers 2

0

$scope.user
   {
        'name':'TestName', 
        'someCustomData': 'Not part of the form',
        'someMoreMetaData': 'Also not part of the from'
    }

Sign up to request clarification or add additional context in comments.

Comments

0

You should add a watch validation and act when valid:

scope.$watch('myForm.myInput.$valid', function(validity) {$scope.user.custom data ="blabla"})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.