I am using angular x-editable in my project. http://vitalets.imtqy.com/angular-xeditable/#editable-row
Everything works fine except for displaying a validation error. Here is my HTML template:
<table class="table"> <thead> <tr> <th>Name</th> <th>Width</th> <th>Length</th> <th>Sheets quantity</th> <th>Low price</th> <th>High price</th> <th>Currency</th> <th></th> </tr> </thead> <tbody> <tr ng-repeat="material in sheetMaterials"> <td> <span editable-text="material.name" e-name="name" e-form="form" e-required> {{ material.name }} </span> </td> <td> <span editable-text="material.width" e-name="width" e-form="form" e-required> {{ material.width }} </span> </td> <td> <span editable-text="material.length" e-name="length" e-form="form" e-required> {{ material.length }} </span> </td> <td> <span editable-text="material.sheets" e-name="sheets" e-form="form" e-required> {{ material.sheets }} </span> </td> <td> <span editable-text="material.priceLow" e-name="priceLow" e-form="form" e-required> {{ material.priceLow }} </span> </td> <td> <span editable-text="material.priceHigh" e-name="priceHigh" e-form="form" e-required> {{ material.priceHigh }} </span> </td> <td> <span editable-select="material.currency" e-ng-options="s.value as s.text for s in currencies" e-name="currency" e-form="form" e-required> {{ showCurrency( material ) }} </span> </td> <td style="white-space: nowrap"> <form editable-form name="form" onaftersave="updateSheetMaterial( $data, material._id, form )" ng-show="form.$visible" class="form-buttons form-inline" shown="inserted == material"> <button type="submit" ng-disabled="form.$waiting" class="btn btn-primary"> Save </button> <button type="button" ng-disabled="form.$waiting" ng-click="form.$cancel()" class="btn btn-default"> Cancel </button> </form> <div class="buttons" ng-show="!form.$visible"> <button class="btn btn-primary" ng-click="form.$show()"> Edit </button> <button class="btn btn-danger" ng-click="removeSheeteMaterial( materials, $index )"> Delete </button> </div> </td> </tr> </tbody> </table> <button class="pull-right btn btn-primary" ng-click="createSheetMaterial()">Add</button>
Here is the controller in which I handle the behavior of the form:
angular.module( 'client' ) .controller( 'materialController', [ '$scope', '$filter', 'sheetMaterialFactory', function( $scope, $filter, sheetMaterialFactory ){ $scope.index = function(){ $scope.currencies = [ { value: 'RUB', text: "" }, { value: 'EUR', text: "โฌ" }, { value: 'USD', text: "$" }, ] sheetMaterialFactory.getList().then( function( materials ){ $scope.sheetMaterials = materials; }); $scope.content = "partials/material.html"; } $scope.showCurrency = function( material ){ var selected = $filter('filter')( $scope.currencies, { value: material.currency }); return ( material.currency && selected.length ) ? selected[ 0 ].text : 'Not set'; } $scope.updateSheetMaterial = function( data, _id, form ){ data._id = _id; var action = data._id ? "update" : "create"; sheetMaterialFactory [ action ]( data ) .then( function( sheetMaterial ){ if( "update" == action ){ var collection = $scope.sheetMaterials; collection = collectionService.updateObject( collection, sheetMaterial ); } else { collection.push( sheetMaterial ); } }, function( error ){ if( error.data.errors ){ angular.forEach( error.data.errors, function( errorData, field ){ form.$setError( field, errorData.message ); }); } else { form.$setError( 'name', ' ' ); } }); } $scope.createSheetMaterial = function( data ){ if( !data ){ var sheetMaterial = { name: "Some name" }; $scope.sheetMaterials.push( sheetMaterial ); return; } } $scope.index(); } ] );
I checked all the small details and saw this shape. $ setError works fine. The error text is indeed assigned to the form element. But after submitting the form, it does not appear. If someone knows how to fix this, your answer will be appreciated.