JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app="myapp" ng-controller="ContactController">
<form name="form" force-bind ng-submit="submit()">
<label for="name">Name:</label>
<input type="text" name="name" id="name" ng-model="contact.name" ng-required="true" />
<label for="obs">Obs:</label>
<textarea name="obs" id="obs" ng-model="contact.obs"></textarea>
<input type="submit" value="Enviar" />
</form>
</div>
JavaScript
var myApp = angular.module('myapp', [
]);
myApp.controller('ContactController', ['$scope', '$http',
function($scope, $http) {
$scope.contact = {};
$scope.submit = function() {
console.log($scope.contact);
$http.post('/contact').success(function(response) {
console.log('Sent!');
});
};
}
]);
myApp.directive('forceBind', function() {
return {
require: '^form',
priority: -1,
link: function (scope, element, attrs, form) {
element.bind('submit', function() {
if (form.$valid) {
angular.forEach(form, function(value, key) {
if (value.hasOwnProperty('$modelValue')) {
if (!value.$viewValue) {
value.$setViewValue("");
}
}
});
}
});
}
};
});