Commit Graph

19 Commits

Author SHA1 Message Date
taitus
923c2a7ee2 Check labels styles
We are use a display: block style for labels containing check boxes inside
them, and the label has a width of 100%.

This means that clicking on the blank space on the right of the label text
will check/uncheck the checkbox. To avoid this behaviour we modify the
"display" attribute of the labels.

In order to prevent unexpected behaviour in terms_of_service form labels,
we add specific css for this case when define a checkbox within the
.actions class.
2022-04-04 18:55:56 +02:00
Javi Martín
1fa05b1f54 Fix crash on attributes with interpolation arguments
The application crashed when we generated hints to attributes with
interpolation arguments in their `human_attribute_name`.

When generating the hint, we used the `custom_label` method to generate
a label and get the `for` attribute and, since we weren't passing a
text, it used the default human attribute name for the field. However,
it crashes if the default attribute name requires an interpolation
argument.

So now, since we were only using the `custom_label` method in order to
get the `for` attribute, we're simply passing an arbitrary text to the
method.
2022-03-28 14:55:42 +02:00
taitus
d719b2291e Do not generate an empty hint element when there's an empty hint 2022-03-28 14:55:42 +02:00
Javi Martín
2c76f265f8 Add and apply Style/NegatedIfElseCondition rule
This rule was added in Rubocop 1.2.0, and will make developers who hate
negative conditions particularly happy.
2021-09-03 11:49:53 +02:00
Javi Martín
cd418e45be Allow hints on select fields
Just like we allow them on input fields.
2020-09-09 12:20:46 +02:00
Javi Martín
fc9a87a8ab Use native HTML5 date fields in the admin section
We've had to add a couple of hacks in order to make jQuery UI datepicker
work with Turbolinks, and one of our tests is failing because the
datepicker changes its height when changing from a month with 5 weeks to
a month with 6 weeks.

We could add a workaround so the test still passes (jQuery UI doesn't
provide a configuration option to always displays 6 weeks in the
datepicker), but I think it's easier to just use the HTML5 native date
input field, which also allows us to simplify the code a bit and IMHO it
improves the user experience, particularly when using mobile phones.

Since date fields are not supported in Safari and Internet Explorer,
we're still using the jQuery UI datepicker on those browsers (and on any
other browser not supporting date fields).

Due to these changes, we're moving the tests checking datepicker's
behaviour to the dashboard. I've choosing not to change the public pages
because I'm not 100% sure everybody would like this change (some people
prefer the datepicker because we can configure the way it looks).
2020-08-28 12:55:58 +02:00
Javi Martín
c5f4cd6229 Fix invalid "hint" attribute in forms
Using `hint: false` was generating an input with `hint="false"` instead
of generating no hint at all.
2020-08-22 23:00:14 +02:00
Javi Martín
f49745d7ba Simplify passing the object in the form builder
The object is already a method, so we don't need to pass it around.
2020-08-22 23:00:14 +02:00
Javi Martín
749428d93f Replace content_tag with new tag builder syntax
One of the main advantages of this syntax is we can now omit the content
parameter when it's empty.
2020-04-27 19:26:37 +02:00
Javi Martín
6ef07f8a54 Use text_area instead of cktext_area
We're going to change CKEditor to an inline editor, and the "ckeditor"
gem doesn't provide an option to do so.

Since using `cktext_area` would automatically generate a "classic"
iframe CKEditor, we need to use `text_area` and load the editor using
JavaScript. Personally I prefer this option anyway.

Note in the jQuery selector we need to use `textarea.html-area`; using
just `.html-area` would fail if there's an error message associated to
the textarea, since Rails will add the `.html-area` class to the error
message.
2019-10-25 16:34:25 +02:00
Javi Martín
17ae9c96dc Fix typos sanitizing checkbox labels 2019-10-21 21:33:58 +02:00
Javi Martín
9a299aeeb5 Fix checkbox label containing links
The link tags were being stripped out by `content_tag`.
2019-10-09 19:46:47 +02:00
Javi Martín
75a28fafcb Sanitize label texts automatically
This way we can remove all those `html_safe` calls and we avoid
potential XSS attacks in label texts.
2019-10-08 18:46:21 +02:00
Javi Martín
4f1131d2e5 Add labels to radio buttons automatically 2019-10-06 20:06:00 +02:00
Javi Martín
aec84f6522 Generate labels for attribute automatically
I'm not sure why it isn't already done by foundation's form builder. It
doesn't make any sense to change an ID of a form field without changing
the `for` attribute of its label.
2019-10-06 19:32:04 +02:00
Javi Martín
8d9cb4d8e3 Simplify generating checkboxes in forms
Using the block syntax to generate the label with a <span> tag inside
isn't necessary after upgrading foundation_rails_helpers. Before the
upgrade, we couldn't do so because the <span> tag was escaped.
2019-10-06 19:32:04 +02:00
Javi Martín
4f5de5be3b Add aria-describedby attribute automatically
We were manually adding the attribute in many places, but not
everywhere. I'm assuming adding it where we didn't have it is doing no
harm.
2019-10-06 19:32:03 +02:00
Javi Martín
4a19bb6b77 Simplify generating fields with hints
We were already using this code in translatable forms. Using it on every
form means we can reduce the code we need to generate a field with a
hint.
2019-10-06 18:03:38 +02:00
Javi Martín
ae6fab9f5e Inherit from builder instead of monkey patching it
We were monkey-patching FoundationRailsHelper::Formbuilder, which made
form customization difficult. We can inherit from it, which is the
standard way of extending what an existing class does, and make our form
the default one.
2019-10-05 16:01:58 +02:00