I am facing an issue where I want to disable the submit button until some text is entered in the input box.
<div id="app-id-input-container" ng-form="appIdInput">
<div class="input-group">
<input id="app-id-input" name="appIdInput" ng-click="clearAppIdInput()" class="form-control" type="text" ng-model="appId" pattern="^[AaIi][PpXxNn][0-9]{6}$" maxlength="8" />
<span class="input-group-btn">
<button id="addAppId" class="btn btn-success" ng-click="preferences.appIdInput.$valid && addAppId()" type="button"> <span class="glyphicon glyphicon-plus"></span></button>
</span>
</div>
<span class="validation-alert" ng-show="appIdError">{{appIdError}}</span>
</div>
To reset the field, I have a function that clears it when a user clicks inside the input box.
$scope.clearAppIdInput = function() {
$scope.appId = "";
};
However, even when the field is empty, the button remains enabled. I have a script to disable the button initially and enable it only when text is entered.
$(document).ready(function(){
$('#addAppId').prop('disabled', true);
$('#app-id-input').keyup(function(){
$('#addAppId').prop('disabled', this.value == "" ? true : false);
});
});
One challenge I'm facing is that pressing "backspace" on the keyboard enables the button again. How can I ensure the button stays disabled only when clearing the input field with a click?