1

I'm new to Angular Schema Form and having some issues with select and checkbox fields required validation.

Under $scope.schema I have the select field named designation:

"designation": {
    "title": "Designation",
    "type": "select",
    "default": undefined
}

$scope.form (declaring designation and agreeTerms):

{
    "key": "designation",
    "type": "select",
    "title": "Designation",
    "titleMap": [
        { value: undefined, name: "Select a designation" }, // first value
        { value: "Andersson", name: "Andersson" },
        { value: "Johansson", name: "Johansson" },
        { value: "other", name: "Something else..."}
    ]
},
{
    "key": "agreeTerms",
    "type": "checkbox",
    "title": "I agree to ..."
}

Both designation and agreeTerms are defined in the schema's required property.

When I submit the form, both fields however pass the required validation. What I'm expecting the UI to show are the Required messages underneath/after the fields. That is not happening.

Things I've tried:

  • assign first value of the select field to '' and null and match that with the schema default value.
  • change the select field type to object in the schema; this worked and passed the required validation but the property didn't show up in the model

Please help :)

2
  • Looks AngularJS not Angular? Commented May 12, 2018 at 4:53
  • @siva636 yes my bad. Thanks to yerkon for the edit. Commented May 12, 2018 at 5:26

1 Answer 1

1

You need to change the schema type to string as select is not a valid schema type property.

"designation": {
    "title": "Designation",
    "type": "string",
    "default": undefined
}

Then in your form tag you should have ng-submit="submitForm(ngform,modelData)":

<form sf-schema="schema" sf-form="form" sf-model="model" ng-submit="submitForm(ngform,modelData)" sf-options="option"></form>

Then within your controller you can broadcast on submit to validate:

$scope.submitForm = function(form) {
    // First we broadcast an event so all fields validate themselves
    $scope.$broadcast('schemaFormValidate');
};
Sign up to request clarification or add additional context in comments.

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.