What practical problem will i face if i use same #id more than one time on a page , other than validation error ID is already defined?
This post is just to add some more points to this interesting discussion ..
Its true that .. Id must have been unique and usage of 'duplicate IDs' must have been depreciated by browsers itself ..
But may be because these browsers want to make it more coder-friendly, don't seriously consider the "id" matter ..
So apart from javascript this mistake doesn't matter much to us too ...
(Depends on the version of the different browsers) Even CSS has no problem with it .. (apart from validation errors) check this out ..
<head>
<style type="text/css">
#Button{color:red;}
</style>
</head>
<body>
<form>
<input id="Button" type="button" value="Click me"/>
<input id="Button" type="text" value="Type Here"/>
</form>
</body>
But I assure that in-case of javascript usage it is prone to hell of bugs .. Once I had faced this problem .. where I had used same name for ID as well as NAME .. !
:-)
html id selectors vs other kinds of selectors
They will all render (to varying degrees) but the consequences are apparent when you use CSS of JS to select on the ID. In that case it may not give you the one you are trying to select. It is undetermined which will get selected and may not be repeatable.
jQuery mouseover continuous slideshow loop
For setInterval
you need to wrap your function inside an anonymous function if you want to pass parameters to it. More info.
hoverInterval = setInterval(function() {doStuff(parameters)}, 1000);
Here is the updated fiddle based on yours. I made a few additional improvements.
You probably want to reset all data when mouse leaves area:
//reset the counter
i= 0;
//reset all slides
$(this).children('.slide').animate({top:'100px'}, 0);
//first one should be in visible area
$(this).children('.slide').eq(0).animate({top:'0px'}, 0);
// stop calling doStuff
clearInterval(hoverInterval);
And also, having a duplicate ID for "slideshow-block" is invalid, should be unique for each of them or use class instead as I did. This is not directly connected to your problem though, but it is good to know because it can cause other problems.
Why Internet marketer using same format on their website?
This "style" comes from treating a webpage as if it were a printed page, such as a piece of junk mail, which is what these sites strongly resemble. It is used by marketroids who care nothing for the medium as long as they get the "buy" message across to as many stupid people as possible. No coder with a conscience, or even a sense of style, would do this.
Is it bad practice to use the same method for SAVE and UPDATE?
Nothing wrong, but you code will be harder to understand, IMHO.
e.g.:
- What does this method do? It's called
create
, but it also edits? - The view is called
shop-create
but it also edits? - Passing a
0
parameter as default for id and trying tofind
it every time is unnecessary.
public function create($id = 0)
{
return view('shop-create' , ['edit'=> Shop::find($id)]);
}
Although you're thinking that you are simplifying your code, you are turning it more complicated since you are breaking the Single Responsibility
principle from SOLID.
It's easier to understand if you have something like the Laravel suggestion.
Also you keep a very common pattern that any Laravel developer will understand, so you can hire someone to take care of your code and do not worry if he will understand.
Is it bad practice to use the same method for SAVE and UPDATE?
Nothing wrong, but you code will be harder to understand, IMHO.
e.g.:
- What does this method do? It's called
create
, but it also edits? - The view is called
shop-create
but it also edits? - Passing a
0
parameter as default for id and trying tofind
it every time is unnecessary.
public function create($id = 0)
{
return view('shop-create' , ['edit'=> Shop::find($id)]);
}
Although you're thinking that you are simplifying your code, you are turning it more complicated since you are breaking the Single Responsibility
principle from SOLID.
It's easier to understand if you have something like the Laravel suggestion.
Also you keep a very common pattern that any Laravel developer will understand, so you can hire someone to take care of your code and do not worry if he will understand.
jQuery validation: change default error message
Add this code in a separate file/script included after the validation plugin to override the messages, edit at will :)
jQuery.extend(jQuery.validator.messages, {
required: "This field is required.",
remote: "Please fix this field.",
email: "Please enter a valid email address.",
url: "Please enter a valid URL.",
date: "Please enter a valid date.",
dateISO: "Please enter a valid date (ISO).",
number: "Please enter a valid number.",
digits: "Please enter only digits.",
creditcard: "Please enter a valid credit card number.",
equalTo: "Please enter the same value again.",
accept: "Please enter a value with a valid extension.",
maxlength: jQuery.validator.format("Please enter no more than {0} characters."),
minlength: jQuery.validator.format("Please enter at least {0} characters."),
rangelength: jQuery.validator.format("Please enter a value between {0} and {1} characters long."),
range: jQuery.validator.format("Please enter a value between {0} and {1}."),
max: jQuery.validator.format("Please enter a value less than or equal to {0}."),
min: jQuery.validator.format("Please enter a value greater than or equal to {0}.")
});
How to display my application's errors in JSF?
In case anyone was curious, I was able to figure this out based on all of your responses combined!
This is in the Facelet:
<h:form id="myform">
<h:inputSecret value="#{createNewPassword.newPassword1}" id="newPassword1" />
<h:message class="error" for="newPassword1" id="newPassword1Error" />
<h:inputSecret value="#{createNewPassword.newPassword2}" id="newPassword2" />
<h:message class="error" for="newPassword2" id="newPassword2Error" />
<h:commandButton value="Continue" action="#{createNewPassword.continueButton}" />
</h:form>
This is in the continueButton() method:
FacesContext.getCurrentInstance().addMessage("myForm:newPassword1", new FacesMessage(PASSWORDS_DONT_MATCH, PASSWORDS_DONT_MATCH));
And it works! Thanks for the help!
Related Topics
How to Use Data Attributes with Font Awesome
Css: How to Combine Multiple Stylesheets into One
Twitter Bootstrap Custom Carousel Indicators
Bootstrap 3 - Add an Asterisk to the Input on the Same Row
Blinking Loading Text in R Shiny
CSS - Position Absolute & Document Flow
Placing a Fixed Element Above Browser's Scrollbar
Google Fonts Font-Weight of 100 Is Not Working
Symfony2, Loading CSS Files Without Cache
CSS Inverted Trapezium When Width Will Differ
Access the Locale in Ruby in CSS Files
Make HTML5 Video Poster Be Same Size as Video Itself
How to Align a Div to The Top of Its Parent But Keeping Its Inline-Block Behaviour