0

I am using Glyphicon icon in my input controls once it finds some error. Glyphicon icon has both error and correct images on it. But I want to clear that input control on clicking of error glyphicon. below is my code:

 <div class="{{layout=='horizontal'? fieldClass || 'col-lg-9':''}} ">
        <div style="position:relative" class="input-group">
            <span class="input-group-addon"><b>PD</b></span>
            <div class="icon-addo addon-md">
                <input type="text" class="form-control {{textboxClass}}" name="textControl" id="textControl" ng-readonly="readonly" ng-required="required"
                       maxlength="10" placeholder="{{placeholder || layout=='inline' ? labelText : ''}}" data-ng-model="vm.value" ng-blur="vm.onBlur()" />

                <i ng-show="vm.state==1" class="form-control-feedback fa fa-spinner fa-spin" style="width: auto; height:auto; font-size: 25px; top:5px; right:10px"></i>
                <i onclick="clearControl(this,'textControl');" class="form-control-feedback" ng-class="{'glyphicon glyphicon-ok': vm.state==2, 'glyphicon glyphicon-remove': vm.state==3}" style="width: auto; height:auto; font-size: 20px; top:0; right:10px"></i>
            </div>
        </div>
        <div ng-show="textForm['textControl'].$error.required && (submitted || !textForm['textControl'].$pristine)" class="help-block ng-hide">{{labelText}} is required</div>
    </div></i>

Please help.

0

1 Answer 1

2

Don't use inline onclick handlers. You can clear input simply with ngClick directive:

<i ng-click="vm.value = ''" class="form-control-feedback" ng-class="{'glyphicon glyphicon-ok': vm.state==2, 'glyphicon glyphicon-remove': vm.state==3}" style="width: auto; height:auto; font-size: 20px; top:0; right:10px"></i>

I would also recommend to clear HTML, move styles to CSS files, it would make you code more comprehensive.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually later on I used ng-click but here I want to call a function instead of direct clearing field here because I want to check some other values in controller also. But your response helped. Thanks.

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.