monterail / guidelines

[DEPRECATED] We are Ruby on Rails experts from Poland. Think hussars. Solid & winged. These are our guidelines.
71 stars 17 forks source link

Use only anchor or button for click actions #212

Closed jandudulski closed 10 years ago

jandudulski commented 10 years ago

Use anchor (a HTML tag element) when click should change page url. Use button type="submit" if click would submit a form. Use button type="button" for any other click actions (e.g. next page with ajax loading, toggle view etc).

venticco commented 10 years ago

input type="submit" is good too, but button type="button" is crucial for buttons inside form that are not dedicated to submitting of this form.

teamon commented 10 years ago

Seems legit.

sheerun commented 10 years ago

ok

hodak commented 10 years ago

I'll just add that it's important to add type="button" because this attribute defaults to submit so just button will try to send the form.

tallica commented 10 years ago

What if I need to use <a> tag combined with ng-click="foo()", what should I put inside href attribute?

In many places the last option is suggested

cc: @venticco @hodak @tommy92 @jandudulski @teamon

venticco commented 10 years ago

If you need to have ng-click action, then you should use <button>, if it need look and behavior of link then use CSS to make it looks like one. <a> without href attribute is improper, empty href can lead into wrong behavior, and last option looks and feels ugly, because of inline JS code.

tallica commented 10 years ago

Yeah it's ugly hack, I know... the problem is that bootstrap uses <a> tags in the components like dropdowns. I would have to change CSS to use buttons.

hodak commented 10 years ago

Hmm, that's a good point. I think in this case it's justified to use a. Do you know the reason behind the javascript:void(0) and why it would be better than href=""?

tallica commented 10 years ago

Not really. Maybe we should combine href="" with prevent-default directive in such cases?

jandudulski commented 10 years ago

@tallica drop the bootstrap :smile: