Comments (6)
Thinking more about this, I would also argue that we should also move the has-error
field to the div instead of the input.
If we do that, we would also solve #159
He is an example of that to the select input:
def select(assigns) do
error_class = if field_has_errors?(assigns), do: "has-error", else: ""
assigns =
assigns |> assign_defaults("pc-select") |> assign(:error_class, error_class)
~H"""
<div phx-feedback-for={Form.input_name(@form, @field)} class={@error_class}>
<%= Form.select(
@form,
@field,
@options,
[class: @classes] ++ Map.to_list(@rest)
) %>
</div>
"""
end
And change the CSS to this:
div.has-error:not(.phx-no-feedback) > select {
@apply !border-red-500 focus:!border-red-500 !text-red-900 !placeholder-red-700 !bg-red-50 dark:!text-red-100 dark:!placeholder-red-300 dark:!bg-red-900 focus:!ring-red-500;
}
from petal_components.
Btw, if you are OK with the change I can create a PR with it for all form components
from petal_components.
One issue could be you now are returning a div instead of an input, which may be unexpected or could create issues with styling. You might want to add styling to that div for layout purposes.
Maybe a halfway point could be adding your new classes so people can wrap their input with <div phx-feedback-for={Form.input_name(@form, @field)}>
and it'll still work with the phx-update="ignore"
? That's what I do with <.form_field>
from petal_components.
Not sure if I understand your suggestion, can you clarify it? Do you mean manually adding the div outside the component? If so, that would work, but I believe that the user would also need to remove/overload the current CSS from petal components and add a new one like the one I showed above.
In that case, it seems to me that the user is better off just copying the full form.ex
file from Petal Components and changing it instead of trying to work around it.
I don't see what is the problem with actually returning the div instead of the input as the root tbh, as long as that div doesn't have any styling on it, it should just be "invisible" to the end user no?
Also, even core_components
does that, seems like that is the "correct" way of handling these cases since inputs have a lot of corner cases (like the select
input discussed in #159).
Edit: Also, if there is a need to allow adding classes/styling that div, then we can just add a new optional attr to the components to add classes to it no?
from petal_components.
Yeah, I meant manually adding a div - perhaps in a new custom component that utilises the <.text_input>
component or whichever one you were using. eg
eg
def my_new_field do
~H"""
<div phx-feedback-for={@field}>
<.form_label form={@form} field={@field} />
<.text_input phx-hook="xxx" field={@field} form={@form} field={@field} />
<.form_field_error form={@form} field={@field} />
</div>
"""
end
The core_components
input function is more like our form_field
function - it contains the label, input and error components.
Can I ask what hook you are implementing?
from petal_components.
Done in v1.1.0 with the new <.field>
component. 791276f
Docs coming soon
from petal_components.
Related Issues (20)
- Request: keep pagination previous & next buttons always visible
- CssSyntaxError The `invalid-feedback` class does not exist. with version 1.0 HOT 3
- Disabled buttons should not just look disabled HOT 5
- Dropdown button always is open HOT 3
- BUG: Namespaced components not working as documented HOT 10
- Bug: Unable to import "../../deps/petal_components/assets/default.css"; in app.css file HOT 10
- Select field will not remove "has-error" class until subsequent update HOT 2
- Q: Support for optimized form field access? HOT 3
- `group-hover/pc-icon-button:flex` class does not exist HOT 4
- checkbox_group form field has an extra empty string HOT 5
- Empty help text adding undesirable margin HOT 1
- Missing `class` attributes for some field types HOT 2
- Missing `class` attribute on `field_label` Forms v2 HOT 3
- Request: individually disable a checkbox when using checkbox-group HOT 2
- v2 form with datetime_select input and builder function does not work HOT 3
- 'rows' attribute in 'textarea' field is not overriden HOT 2
- Petal Component Form fields require field name as atom - running out of atoms? HOT 1
- 'selected' attribute is not working on 'select' type fields on v2 Forms HOT 2
- compile error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from petal_components.