Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form input data-error does not show. #1752

Closed
ronanversendaal opened this issue Jul 17, 2015 · 7 comments
Closed

Form input data-error does not show. #1752

ronanversendaal opened this issue Jul 17, 2015 · 7 comments
Labels

Comments

@ronanversendaal
Copy link

First of all I would like to say how happy i am with this framework. It has provided me with many features I like to use. I would like to insert form errors on my contact form when it is not filled in correctly. Unfortunately, using the attributes data-error and data-success does nothing to the input and I have not seen an open issue on this yet.

I am using the following markup:

<i class="material-icons prefix">account_circle</i>
    <input id="name" type="text" class="validate">
    <label for="name">Name</label>
</div>

2015-07-17 23_18_53-portfolio

I am programmaticly adding the data-error="name is required" once the form has not been filled in correctly. I have checked the javascript and I can see in the console that the data-error attribute is inserted into the corresponding label, but nothing changes. Adding the attributes natively also does not make any changes.

Please help me out. I will provide further information if needed.

@exp0nge
Copy link

exp0nge commented Jul 19, 2015

You can use jQuery to add the errors.
e.g.

$('#error-message').html('<div class="card-panel red">' + errors+ '</div>');

@Clemzd
Copy link

Clemzd commented Jul 19, 2015

I think using attr jquery function is a better practise and it works fine for me.
Considering you have your label in a variable called $label you can do

$label.attr('data-error','The name field is required');

Btw I don't know what is your needs but I have made an example for jquery-validation to be compatible with materialize if you're interested : https://jsfiddle.net/rz0zk5u6/2/

@Dogfalo
Copy link
Owner

Dogfalo commented Jul 30, 2015

Perhaps you are on an older build which did not support these.

@inyerade
Copy link

works with

$("#id").attr('data-error' , 'new text')

but not works with

$("#id").data('error' , 'new text')

@ipereto
Copy link

ipereto commented Dec 1, 2016

@Clemzd This code not work when change class of the field datefield to datepicker of materializecss, because the attribute data-error is present but it is not show in the frontend. I see that ::after is not present. Anyone know what happend with this? I'm trying to fix this, but we can solve it together easyly.

Sorry for my english.

image

You can see in the image that ::after in into the label Standard Field 2, but in the date field ::after is not present and I think that for that reason data-error is not present in the UI.

@ipereto
Copy link

ipereto commented Dec 2, 2016

Hello guys,

Thank you @Clemzd, I use your code to implement a datepicker and select to test the data-error in these fields.

https://jsfiddle.net/ipereto/28maedmf/

@ronanversendaal, I hope this can help to everyone that require this type of validation with materializecss in your software.

@fega fega closed this as completed Apr 13, 2017
@fega fega added the question label Apr 13, 2017
@khuznain
Copy link

You can use this code

$(document).on("blur", ".required", function (e) {
e.preventDefault();
//validate forms
if ($(this).val() === "") {
$(this).addClass("invalid");
$(this).parent().find("label").addClass("active");
} else {
$(this).removeClass("invalid");
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants