2

I have a problem. I want to run a function but it can only be run when I'm 100% sure the required fields are filled.

ATM it just executes the function even tho the required fields are not filled.

<input id="ticket-title" uib-tooltip="Insert a title for the ticket" 
       class="ticket-title" name="title" type="text"
       placeholder="Write a title for the ticket" ng-model="vm.ticket.TITLE" required>
<button type="submit" class="btn btn-default p1" ng-click="vm.createTicket()">
    Submit <i class="glyphicon glyphicon-ok"></i>
</button>

Controller

vm.createTicket = function () {
    // I need a way to check if the form/fields are filled.
};
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

2 Answers2

0

Give your input a model like:

<input id="ticket-title" ng-model="ticket" placeholder="Insert ticket title"/>

and in your JS do this:

if ($scope.ticket!= null && $scope.ticket!= "") {
    //do something
}
Zeeshan Adil
  • 1,937
  • 5
  • 23
  • 42
0
  <input id="ticket-title" uib-tooltip="Insert a title for the ticket" 
   class="ticket-title" name="title" type="text"
   placeholder="Write a title for the ticket" ng-model="vm.ticket.TITLE" 
   required>
   <button type="submit" class="btn btn-default p1" 
    ng-disabled="vm.disableTicket()" ng-click="vm.createTicket()">
   Submit <i class="glyphicon glyphicon-ok"></i>
   </button>


  Controller :
 vm.disableTicket = function() {
   return !vm.ticket.TITLE;
 }
Prachi Varaiya
  • 175
  • 1
  • 9