-
Notifications
You must be signed in to change notification settings - Fork 24
Formless fields #216
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
Comments
The only reason I find for this is for the field components to be really reusable anywhere in the code. That what you expect from the components you declare, not only form-related. As a consequence of being formless, you won't be able to access |
This change also means decentralization of the field events handling, and event callbacks. As for now, any field interaction emits the respective event, the latter is being caught by the form observables, and being handled properly. Form is also the place responsible for dispatching various callback methods (i.e.
I don't know how I feel about this overview. This most likely means a huge rework of the architecture, and I think it's not worth the trouble. Alternatively, formless fields may be just super diminished versions of full-scale fields. I am okay with the changes if it's approximately like this: if (this.context.form) {
return handleFieldAsNormal();
}
handleFieldAsFormless(); |
Summing things up. The issues1. Where to keep the field's state once it's formless?Now the fields' state are kept in the form's state. Once the form is gone, formless field must contain its own state by itself. SolutionFormless fields are stateful, containing their own field state. 2. How to mutate the field's state?All field state mutation actions (fieldChange, fieldBlur, etc.) are kept in the form. Formless field must use some other way of mutating the field's state. SolutionI keep thinking of pure functions which take the current field state, additional data, and produce the next field state. This would be a functional way of form implementation. Then, the form component itself would reuse those pure functions as well. A couple of pure function examples: function handleFieldChange({ fieldProps, fields, form, nextValue }) {
return fieldProps.set(fieldProps.get('valuePropName'), nextValue);
}
function validateField({ fieldProps, fields, form }) {
const nextValidityState = fieldUtils.validate({ ... });
return fieldProps.merge(nextValidityState);
} |
UpdateIt has just occurred to me, that it is possible to understand whether the field is formless on the That way, in case of formless fields, HOC could act as a field's state accumulator, a replacement for Form in terms of field-form communication. This way field component remains as is, it keeps communicating up as is, as if there is always a form. Instead, |
@Vidlec In case you started to work on this feature, please align with me. I'm preparing the architectural changes to RAF (#250), one of the points of which is to isolate the whole logic into bunch of pure functions. That will help tremendously to use the same composite handlers on the Let me know if anything! |
Any news on this? I'd like to use Maybe renderless component, something like Big up and thanks for development this part of UI\UX with React! |
Hi, @nickensoul. Thanks for the kind words! Let me update you. Technical backgroundThe biggest task here is to replace the I would say that from the technical perspective a solution to support formless fields is somewhat clear. It would be good to implement (or prepare for) formless fields under #324. I'm currently working on #354, which improves event handlers that would grant less control to the Form, and more to the events. What now?I understand both a desire to use a form element without a wrapping Form, and a conceptual idea behind a form input (to gather data for a form). Nevertheless, I still think that formless fields is worth implementing, but I would also encourage developers to expect less functionality from a formless field. This implementation is on the roadmap, but I would put #324 and #232 as the highest priority. Functionality limitations
|
Wow, appreciate such fast and detailed reply! Thanks, @kettanaito. |
Considering the limitations that @kettanaito has mentioned, I don’t think making any field formless should introduce any breaking changes, also I am assuming that it should respect the global validation rules and messages. |
@nickensoul, yes, your understanding is correct. We use RAF on production, and at the moment we wrap each field we tend to use outside of a form with an explicit Form component to ensure proper communication (such use cases are few, however). The future plan is to refactor this communication, which would potentially allow formless fields. As I've mentioned above, True, @redraushan, it shouldn't be a breaking change. Communication updates and adoption of new context API will cause changes internally, but I would strive to sustain the existing API as-is. There is already a list of suggested API change proposals for |
Uh oh!
There was an error while loading. Please reload this page.
What
Need to consider a formless usage of field components.
Why
Right now when a field component is rendered and is unable to find any ancestor Form, it will throw an error during the record registration. This may be confusing for the beginning developers.
However, it is also reasonable to insist to wrap fields in
Form
. Fields compose a form, so there must be a form. This suggestion requires discussion.Specification
a) A field is considered formless when it doesn't have a wrapping
<Form>
component.a) A formless field cannot access
fields
andform
within any callback/handler methods.b) A formless field cannot access
fields
andform
in any validation resolvers.c) A formless field behaves as a plain
input
field. That implies, it is uncontrolled by default, and can be made controlled by providing avalue
prop and a change handler function.d) (???) A formless field can still accept field enhancers.
e) A formless field doesn't benefit from any form behaviors (serialization, validation, etc.).
The text was updated successfully, but these errors were encountered: