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

Ability to bind to complex control values #7

Open
colinscotttrapeze opened this issue Dec 4, 2023 · 0 comments
Open

Ability to bind to complex control values #7

colinscotttrapeze opened this issue Dec 4, 2023 · 0 comments

Comments

@colinscotttrapeze
Copy link
Contributor

colinscotttrapeze commented Dec 4, 2023

Given data:

{
  from: '2023-04-01',
  to: '2023-05-01',
}

It should be possible to map a value to a control that takes a value in the format of:

{
  startDate: '2023-04-01',
  endDate: '2023-05-01',
}

Given HTML markup:

  <!-- prefer this but not sure it will work due to case insensitive attribute names -->
  <my-date-range bind-startdate="/from" bind-enddate="/to"></my-date-range>
  <!-- otherwise this might work -->
  <my-date-range bind="{ startDate: '/from', endDate: '/to' }"></my-date-range>

And given a control binder of:

const dateRangeBinder = {
    controlSelector: 'my-date-range',
    initializeEvents: (element, onChange) => {
        element.addEventListener('change', async (event, ctx) => {
            const dateRange = {
               [ctx.bind.startDate]: event.detail.value.startDate,
               [ctx.bind.endDate]: event.detail.value.endDate,
            }
            onChange(value);
        });
    },
    writeValue: (control, value) => {
        control.value = {
            startDate: value.startDate,
            endDate: value.endDate,
        }
    },
};
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

1 participant