Is it possible to turn validation into error of the form in the Angular?

0

It's even hard to explain. I have a form that checks a field if it is greater than zero. If so, I'll give the user a message. I want to turn this into a form error because, I can only release the save button if the form is error-free. I wonder if it's possible to do that. Here's my source (I could not format it in a way that I can get cute here):

<form #lancamentoForm="ngForm">
<div class="ui-g-12 ui-md-3 ui-fluid">
            <label>Valor</label>
            <input pInputText type="text" placeholder="0,00" currencyMask name="valor" #valor="ngModel"
                   [options]="{ prefix: '', thousands: '.', decimal: ',', allowNegative: false }" ngModel>
            <div *ngIf="valor.value <= 0 && valor.dirty" class="ui-message ui-message-error">
              Valor deve ser maior que 0
            </div>
          </div>
<button type="submit" pButton label="Salvar" [disabled]="lancamentoForm.invalid"></button>
</form> 

I want to make sure that when the message 'Value greater than 0' is released, the FormatForm will be invalid for the button treatment. It's possible? Thanks!

    
asked by anonymous 28.12.2018 / 15:06

1 answer

0

Now you can create a validation in the css class that disables the button if the value is less than or equal to 0.

And for this you only have to use the ng-disabled button and it would be close to that:

<button ng-model="button" ng-disabled="valor.value <= 0 && valor.dirty">Button</button>

References

    
28.12.2018 / 16:34