Last active
August 29, 2015 14:16
-
-
Save binnyg/bc7df2858c13b7c7c10a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.schema = { | |
"type": "object", | |
"title": "Comment", | |
"properties": { | |
"picture": { | |
"title": "Picture", | |
"type" : "object" | |
}, | |
"email": { | |
"title": "Email", | |
"type": "string", | |
"pattern": "^\\S+@\\S+$", | |
"description": "Email will be used for evil." | |
}, | |
"comment": { | |
"title": "Comment", | |
"type": "string", | |
"maxLength": 20, | |
"validationMessage": "Don't be greedy!" | |
} | |
}, | |
"required": [ | |
"email", | |
"comment" | |
] | |
}; | |
$scope.form = [ | |
{ | |
"key" : "picture", | |
"type" : "dfFile" | |
}, | |
"email", | |
{ | |
"key": "comment", | |
"type": "textarea", | |
"placeholder": "Make a comment" | |
}, | |
{ | |
"type": "submit", | |
"style": "btn-info", | |
"title": "OK" | |
} | |
]; | |
$scope.model = {}; | |
$scope.onSubmit = function(form) { | |
// First we broadcast an event so all fields validate themselves | |
$scope.$broadcast('schemaFormValidate'); | |
// Then we check if the form is valid | |
if (form.$valid) { | |
console.log('form is valid'); | |
} else { | |
console.log('form is not valid'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="form-group" ng-class="{'has-error': hasError()}"> | |
<label class="control-label" ng-show="showTitle()">{{form.title}}</label> | |
<input ng-show="form.key" | |
type="file" | |
ng-file-select | |
class="form-control" | |
schema-validate="form" | |
ng-model="$$value$$"/> | |
<div class="help-block" | |
ng-show="(hasError() && errorMessage(schemaError())) || form.description" | |
ng-bind-html="(hasError() && errorMessage(schemaError())) || form.description"></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('dfApp').config( | |
['schemaFormProvider', 'schemaFormDecoratorsProvider', 'sfPathProvider', | |
function(schemaFormProvider, schemaFormDecoratorsProvider, sfPathProvider) { | |
schemaFormDecoratorsProvider.addMapping( | |
'bootstrapDecorator', | |
'dfFile', | |
'scripts/app/dynaforms/decorators/dfFile.html' | |
); | |
schemaFormDecoratorsProvider.createDirective( | |
'dfFile', | |
'scripts/app/dynaforms/decorators/dflowFile.html' | |
); | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment