Skip to content

Optional/required label formatting #275

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

Closed
1 task done
kav opened this issue Jul 12, 2016 · 8 comments
Closed
1 task done

Optional/required label formatting #275

kav opened this issue Jul 12, 2016 · 8 comments

Comments

@kav
Copy link

kav commented Jul 12, 2016

Prerequisites

Description

Per https://uxdesign.cc/design-better-forms-96fadca0f49c#.mmbenef8x it'd look a heck of a lot nicer if optional params had -Optional labels rather than required ones having a star.

Alternatively we might be able to move that into CSS so the asterisk or optional text could be controlled there.

I get that some people likely prefer the current behavior so I'd love to see ideas on where to control this otherwise.

Happy to investigate here if a pull request of some kind would be welcomed

@n1k0
Copy link
Collaborator

n1k0 commented Jul 12, 2016

Sure, that's something I wanted to do for a while. A first step could be to just update the existing code to use what this post suggests; the thing is that we don't want to introduce specific stylesheets/styles to avoid introducing too much coupling with the bootstrap semantics.

I've been thinking for a while that we could provide a field template option, basically a stateless component providing the component pieces needed to render a whole field from its props:

// dumb example, more props would be exposed
function MyFieldTemplate({id, label, required, errors, children}) {
  return (
    <div className="my-field">
      <label htmlFor={id}>{label}{required ? "*" : ""}</label>
      {children}
      {errors}
    </div>
  );
}

render(<Form fieldTemplate={MyFieldTemplate} />);

What do you think?

@n1k0
Copy link
Collaborator

n1k0 commented Jul 12, 2016

A first step could be to just update the existing code to use what this post suggests

Done that in #276, feedback welcome.

@cedricmessiant
Copy link
Contributor

This field template thing would be great !
(a few months ago, I had to create a complete SchemaField just to get the markup I needed for my fields).

@kav
Copy link
Author

kav commented Jul 14, 2016

I like the update although it feels a bit like trading one issue for another. Fundamentally this is a form styling question rather than a content one so anything that injects content seems less ideal. Controlling for some formatting of the optional text would be ideal. Injecting fields is handy but seems like overkill for this use case (I can see a few others for sure)

I think a better solution is to simply add a class "form-label-required" or something like that to the label associated with the required control. Then it is crazy easy to control the behavior via css. See this fiddle for an example I threw together. Obviously in react you might put the css in the component style but you get the idea.

https://jsfiddle.net/514r2f18/4/

@olzraiti
Copy link
Contributor

A template system would be a game changer indeed!

@pablen
Copy link
Contributor

pablen commented Jul 18, 2016

Maybe something like labelRenderer prop from react-json-tree would be nice?

https://github.com/alexkuz/react-json-tree#customize-rendering

This was referenced Jul 18, 2016
@n1k0
Copy link
Collaborator

n1k0 commented Jul 20, 2016

I think #284 would address all these quite concerns nicely.

@n1k0
Copy link
Collaborator

n1k0 commented Aug 19, 2016

Now #304 has landed, you have full control over how the labels are rendered. Closing this.

@n1k0 n1k0 closed this as completed Aug 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants