Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validations of the input
Message
De
07/09/2017 03:54:22
 
 
Information générale
Forum:
AngularJS
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01653867
Message ID:
01654071
Vues:
41
>Hi Viv,
>
>I'm not exactly sure if I'm going in the right direction. Here is what I wrote so far:
>
>API Code
>
>
>[Route("checkCodeUniqueness")]
>        [HttpPut]
>        public IHttpActionResult CheckCodeUniqueness(UniquenessTestViewModel testModel)
>        {
>            UniquenessTest model = AutoMapperConfig.Mapper.Map<UniquenessTest>(testModel);
>            String errorMessage = _itemAdapter.CheckCodeUniqueness(model);
>
>            testModel.ErrorMessage = errorMessage;
>            testModel.IsValid = String.IsNullOrEmpty(errorMessage);
>
>            return Ok(testModel);
>        }
>
>Is it right or I should somehow throw an error? And if yes, what should it be?
>
>And for the directive I wrote:
>
>
>(function (angular) {
>    "use strict";
>
>    var services,
>        $log,
>        resourceFactory;
>
>    angular.module("sysMgrApp").directive("smCodeUniqueValidator", ["ServiceLoader", smCodeUniqueValidator]);
>
>    /**
>     * smCodeUniqueValidator Directive
>     * @param {} serviceLoader 
>     * @returns {Object} 
>     */
>    function smCodeUniqueValidator(serviceLoader) {
>        services = serviceLoader;
>        $log = services.Log.getInstance("smCodeUniqueValidator");
>        resourceFactory = services.Resource;
>
>        return {
>            restrict: "E",
>            require: "ngModel",
>            
>            scope: {
>                primaryKey: "=?",
>                tableName: "=?",
>                columnToTest: "=?"
>            },
>
>            link: function ($scope, element, attrs, ngModel) {
>                $log.debug("Link is firing...");
>                ngModel.$asyncValidators.codeUnique = function (value) {
>                    var codeObject = {
>                        id: $scope.primaryKey, tableName: $scope.tableName,
>                                        columnToTest: $scope.columnToTest, code: value
>                    };
>                    return services.Item.checkCodeUniqueness(codeObject);
>                };
>            }
>        };
>    }
>})(angular);
>
>In my form I added
>
>
><div class="col-xs-6">
>            <div class="controls">
>                <label class="control-label"
>                       ng-hide="editRetailTrackingForm.barcode.$error.maxlength && editRetailTrackingForm.barcode.$dirty">
>                    @Labels.barcode:
>                </label>
>                <label class="field-validation-error control-label-error animate-show"
>                       ng-show="editRetailTrackingForm.barcode.$error.maxlength && editRetailTrackingForm.barcode.$dirty">
>                    @String.Format(Messages.cannotExceed, Labels.barcode, "100")
>                </label>
>                <div ng-class="{loading:editRetailTrackingForm.barcode.$pending}">
>                <input type="text" name="barcode"
>                       ng-model="currentItem.barcode"
>                       sm-code-unique-validator
>                       table-name="items"
>                       column-to-test="barcode"
>                       primary-key="{{currentItem.itemId}}"
>                       ng-model-options="{ debounce: { default : 500, blur: 0 }}"
>                       class="form-control"
>                       ng-maxlength="100" />
>                    </div>
>            </div>
>        </div>
>
>and then I tried to debug in VS 2017 but nothing happened at all. My validation code is not firing. Do you see what may be wrong? I did add the js file in the bundle.config.

I see that you've got the directive to fire but what is this returning : return services.Item.checkCodeUniqueness(codeObject);
Don't forget that this must be promise that will be resolved or rejected.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform