Input type=“number” multiples validation error messages with clr-control-error












0















I'm working now with Clarity in a personal project, I like so much this Design System, so I will stay asking a lot (sorry for that).



I was trying today to implement multiples validation message errors for a type number input into a form. Docs explains that I should use *clr-control-error to achieve that but it has been impossible.



At the moment validating type number input to show a "required" text works just fine.



View post on imgur.com



But what about if user try to type a letter in the field? It happen with 'e' character. In that case, I want to show another text like "Invalid parameter" or something related.



View post on imgur.com



I was trying do this:



<clr-input-container>
<label class="clr-col-4 clr-col-md-4">Precio de Costo</label>
<input class="clr-col-8 clr-col-md-8" clrInput type="number" formControlName="precioCosto" />
<clr-control-error *clrIfError="'required'">Requerido</clr-control-error>
<clr-control-error *clrIfError="'invalid'">Parámetro Inválido</clr-control-error>
</clr-input-container>


But always show the first message. I was also trying to do with *ngIf but look like there is a conflict with *clr-control-error.



Did you get some way to solve this? I will very grateful with you help.



Update: adding Controller code to clarify issue:



import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators, FormGroup } from '@angular/forms';

@Component({
selector: 'app-productos',
templateUrl: './productos.component.html',
styleUrls: ['./productos.component.scss']
})
export class ProductosComponent implements OnInit {

private productoForm: FormGroup;

constructor(
private fb: FormBuilder
) { }

ngOnInit() {
this.setProductoForm();
}

get f() { return this.productoForm.controls; }

setProductoForm() {
this.productoForm = this.fb.group({
id: [this.productos.length + 1],
nombre: ['', Validators.required],
laboratorio: ['', Validators.required],
unidadMedida: ['', Validators.required],
precioCosto: ['', Validators.required],
precioVenta: ['', Validators.required]
});
}
}









share|improve this question

























  • Can you provide the code where you create your form controls in the controller?

    – Jeremy Wilken
    Dec 24 '18 at 14:39











  • Done, @JeremyWilken.

    – César Gómez
    Dec 25 '18 at 21:00
















0















I'm working now with Clarity in a personal project, I like so much this Design System, so I will stay asking a lot (sorry for that).



I was trying today to implement multiples validation message errors for a type number input into a form. Docs explains that I should use *clr-control-error to achieve that but it has been impossible.



At the moment validating type number input to show a "required" text works just fine.



View post on imgur.com



But what about if user try to type a letter in the field? It happen with 'e' character. In that case, I want to show another text like "Invalid parameter" or something related.



View post on imgur.com



I was trying do this:



<clr-input-container>
<label class="clr-col-4 clr-col-md-4">Precio de Costo</label>
<input class="clr-col-8 clr-col-md-8" clrInput type="number" formControlName="precioCosto" />
<clr-control-error *clrIfError="'required'">Requerido</clr-control-error>
<clr-control-error *clrIfError="'invalid'">Parámetro Inválido</clr-control-error>
</clr-input-container>


But always show the first message. I was also trying to do with *ngIf but look like there is a conflict with *clr-control-error.



Did you get some way to solve this? I will very grateful with you help.



Update: adding Controller code to clarify issue:



import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators, FormGroup } from '@angular/forms';

@Component({
selector: 'app-productos',
templateUrl: './productos.component.html',
styleUrls: ['./productos.component.scss']
})
export class ProductosComponent implements OnInit {

private productoForm: FormGroup;

constructor(
private fb: FormBuilder
) { }

ngOnInit() {
this.setProductoForm();
}

get f() { return this.productoForm.controls; }

setProductoForm() {
this.productoForm = this.fb.group({
id: [this.productos.length + 1],
nombre: ['', Validators.required],
laboratorio: ['', Validators.required],
unidadMedida: ['', Validators.required],
precioCosto: ['', Validators.required],
precioVenta: ['', Validators.required]
});
}
}









share|improve this question

























  • Can you provide the code where you create your form controls in the controller?

    – Jeremy Wilken
    Dec 24 '18 at 14:39











  • Done, @JeremyWilken.

    – César Gómez
    Dec 25 '18 at 21:00














0












0








0








I'm working now with Clarity in a personal project, I like so much this Design System, so I will stay asking a lot (sorry for that).



I was trying today to implement multiples validation message errors for a type number input into a form. Docs explains that I should use *clr-control-error to achieve that but it has been impossible.



At the moment validating type number input to show a "required" text works just fine.



View post on imgur.com



But what about if user try to type a letter in the field? It happen with 'e' character. In that case, I want to show another text like "Invalid parameter" or something related.



View post on imgur.com



I was trying do this:



<clr-input-container>
<label class="clr-col-4 clr-col-md-4">Precio de Costo</label>
<input class="clr-col-8 clr-col-md-8" clrInput type="number" formControlName="precioCosto" />
<clr-control-error *clrIfError="'required'">Requerido</clr-control-error>
<clr-control-error *clrIfError="'invalid'">Parámetro Inválido</clr-control-error>
</clr-input-container>


But always show the first message. I was also trying to do with *ngIf but look like there is a conflict with *clr-control-error.



Did you get some way to solve this? I will very grateful with you help.



Update: adding Controller code to clarify issue:



import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators, FormGroup } from '@angular/forms';

@Component({
selector: 'app-productos',
templateUrl: './productos.component.html',
styleUrls: ['./productos.component.scss']
})
export class ProductosComponent implements OnInit {

private productoForm: FormGroup;

constructor(
private fb: FormBuilder
) { }

ngOnInit() {
this.setProductoForm();
}

get f() { return this.productoForm.controls; }

setProductoForm() {
this.productoForm = this.fb.group({
id: [this.productos.length + 1],
nombre: ['', Validators.required],
laboratorio: ['', Validators.required],
unidadMedida: ['', Validators.required],
precioCosto: ['', Validators.required],
precioVenta: ['', Validators.required]
});
}
}









share|improve this question
















I'm working now with Clarity in a personal project, I like so much this Design System, so I will stay asking a lot (sorry for that).



I was trying today to implement multiples validation message errors for a type number input into a form. Docs explains that I should use *clr-control-error to achieve that but it has been impossible.



At the moment validating type number input to show a "required" text works just fine.



View post on imgur.com



But what about if user try to type a letter in the field? It happen with 'e' character. In that case, I want to show another text like "Invalid parameter" or something related.



View post on imgur.com



I was trying do this:



<clr-input-container>
<label class="clr-col-4 clr-col-md-4">Precio de Costo</label>
<input class="clr-col-8 clr-col-md-8" clrInput type="number" formControlName="precioCosto" />
<clr-control-error *clrIfError="'required'">Requerido</clr-control-error>
<clr-control-error *clrIfError="'invalid'">Parámetro Inválido</clr-control-error>
</clr-input-container>


But always show the first message. I was also trying to do with *ngIf but look like there is a conflict with *clr-control-error.



Did you get some way to solve this? I will very grateful with you help.



Update: adding Controller code to clarify issue:



import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators, FormGroup } from '@angular/forms';

@Component({
selector: 'app-productos',
templateUrl: './productos.component.html',
styleUrls: ['./productos.component.scss']
})
export class ProductosComponent implements OnInit {

private productoForm: FormGroup;

constructor(
private fb: FormBuilder
) { }

ngOnInit() {
this.setProductoForm();
}

get f() { return this.productoForm.controls; }

setProductoForm() {
this.productoForm = this.fb.group({
id: [this.productos.length + 1],
nombre: ['', Validators.required],
laboratorio: ['', Validators.required],
unidadMedida: ['', Validators.required],
precioCosto: ['', Validators.required],
precioVenta: ['', Validators.required]
});
}
}






vmware-clarity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 25 '18 at 20:58







César Gómez

















asked Dec 23 '18 at 20:59









César GómezCésar Gómez

214




214













  • Can you provide the code where you create your form controls in the controller?

    – Jeremy Wilken
    Dec 24 '18 at 14:39











  • Done, @JeremyWilken.

    – César Gómez
    Dec 25 '18 at 21:00



















  • Can you provide the code where you create your form controls in the controller?

    – Jeremy Wilken
    Dec 24 '18 at 14:39











  • Done, @JeremyWilken.

    – César Gómez
    Dec 25 '18 at 21:00

















Can you provide the code where you create your form controls in the controller?

– Jeremy Wilken
Dec 24 '18 at 14:39





Can you provide the code where you create your form controls in the controller?

– Jeremy Wilken
Dec 24 '18 at 14:39













Done, @JeremyWilken.

– César Gómez
Dec 25 '18 at 21:00





Done, @JeremyWilken.

– César Gómez
Dec 25 '18 at 21:00












1 Answer
1






active

oldest

votes


















0














The letter e is a valid character in a number field when you use it with a digit as well, since that is a way to denote exponents. There may be inconsistencies in browsers about how they handle this but here is the spec https://www.w3.org/TR/html5/sec-forms.html#number-state-typenumber. This is really as expected since you've not put in a required value yet, so you get require error type. There are other characters like - that might be typed in the field but still not a value by themselves.



You could write your own validator to handle these cases on your own. There is no invalid validator by default, you'd have to write it, see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53907115%2finput-type-number-multiples-validation-error-messages-with-clr-control-error%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The letter e is a valid character in a number field when you use it with a digit as well, since that is a way to denote exponents. There may be inconsistencies in browsers about how they handle this but here is the spec https://www.w3.org/TR/html5/sec-forms.html#number-state-typenumber. This is really as expected since you've not put in a required value yet, so you get require error type. There are other characters like - that might be typed in the field but still not a value by themselves.



    You could write your own validator to handle these cases on your own. There is no invalid validator by default, you'd have to write it, see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation.






    share|improve this answer




























      0














      The letter e is a valid character in a number field when you use it with a digit as well, since that is a way to denote exponents. There may be inconsistencies in browsers about how they handle this but here is the spec https://www.w3.org/TR/html5/sec-forms.html#number-state-typenumber. This is really as expected since you've not put in a required value yet, so you get require error type. There are other characters like - that might be typed in the field but still not a value by themselves.



      You could write your own validator to handle these cases on your own. There is no invalid validator by default, you'd have to write it, see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation.






      share|improve this answer


























        0












        0








        0







        The letter e is a valid character in a number field when you use it with a digit as well, since that is a way to denote exponents. There may be inconsistencies in browsers about how they handle this but here is the spec https://www.w3.org/TR/html5/sec-forms.html#number-state-typenumber. This is really as expected since you've not put in a required value yet, so you get require error type. There are other characters like - that might be typed in the field but still not a value by themselves.



        You could write your own validator to handle these cases on your own. There is no invalid validator by default, you'd have to write it, see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation.






        share|improve this answer













        The letter e is a valid character in a number field when you use it with a digit as well, since that is a way to denote exponents. There may be inconsistencies in browsers about how they handle this but here is the spec https://www.w3.org/TR/html5/sec-forms.html#number-state-typenumber. This is really as expected since you've not put in a required value yet, so you get require error type. There are other characters like - that might be typed in the field but still not a value by themselves.



        You could write your own validator to handle these cases on your own. There is no invalid validator by default, you'd have to write it, see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 18:21









        Jeremy WilkenJeremy Wilken

        5,7491519




        5,7491519
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53907115%2finput-type-number-multiples-validation-error-messages-with-clr-control-error%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas

            Can't read property showImagePicker of undefined in react native iOS