Skip to content
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

Simplify custom bindings (override default bindings template) #497

Closed
rosieks opened this issue Apr 2, 2019 · 1 comment
Closed

Simplify custom bindings (override default bindings template) #497

rosieks opened this issue Apr 2, 2019 · 1 comment

Comments

@rosieks
Copy link

rosieks commented Apr 2, 2019

I want to change way how name should be generated. As far as I understand I have to do something like that. First create binding template like this:

const formBindings = {
  'pathAsName': ({ $try, field, props }: any) => ({
    id: $try(props.id, field.id),
    name: $try(props.name, field.path),
    type: $try(props.type, field.type),
    value: $try(props.value, field.value),
    label: $try(props.label, field.label),
    placeholder: $try(props.placeholder, field.placeholder),
    disabled: $try(props.disabled, field.disabled),
    onChange: $try(props.onChange, field.onChange),
    onBlur: $try(props.onBlur, field.onBlur),
    onFocus: $try(props.onFocus, field.onFocus),
    autoFocus: $try(props.autoFocus, field.autoFocus),
  }),
};

Then apply it to all fields in my forms.

const bindings = {
   'field1': 'pathAsName',
   'field2': 'pathAsName',
   'field3': 'pathAsName',
   'field4': 'pathAsName',
   'field5': 'pathAsName',
   'field6': 'pathAsName',
   'field7': 'pathAsName',
};

It would be much more easier if I could provide just function that override existing one:

const formBindings = ({ $try, field, props}) => ({
   name: $try(props.name, field.path)
});
@foxhound87
Copy link
Owner

Good point, I will think about a solution.

@foxhound87 foxhound87 changed the title Simplify custom bindings Simplify custom bindings (default bindings template) Mar 9, 2023
@foxhound87 foxhound87 changed the title Simplify custom bindings (default bindings template) Simplify custom bindings (override default bindings template) Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants