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

Show a default value in a dropdown if no option is selected from it #68

Open
VedantSG123 opened this issue Jun 27, 2024 · 2 comments
Open
Labels
bug Something isn't working enhancement New feature or request PR welcome You can open a PR for this issue

Comments

@VedantSG123
Copy link

allowEmpty not working properly
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
I want to restrict the user from setting the cron value to '*' in a particular dropdown.

Current Behaviour:
If the user deselects all the values from the dropdown, it sets the value of that dropdown to '*'

Screencast.from.2024-06-27.10-47-57.mp4

I don't want the value to become * when user deselects all the values from the hour dropdown, instead set it to some default value (not *).

Here is what I tried to do:

export const CronForWeekly = () => {
  const [value, setValue] = React.useState('0 12 * * 7');

  const filterExpr = (value: string) => {
    const exprArray = value.split(' ');
    const hourIndex = 1;

    if (exprArray[hourIndex] === '*') {
      exprArray[hourIndex] = '12';
    }

    setValue(exprArray.join(' '));
  };

  return (
    <div className='flex flex-col gap-4'>
      <div></div>
      <h3>Cron Value</h3>
      <div>{value}</div>
      <Cron
        value={value}
        setValue={filterExpr}
        clearButton={false}
        mode='single'
        defaultPeriod='week'
        allowedDropdowns={['hours', 'minutes', 'week-days']}
        clockFormat='12-hour-clock'
        allowClear={false}
        allowEmpty='never'
      />
    </div>
  );
};

But is not working properly, here is the attached screen record:

Screencast.from.2024-06-27.10-56-27.webm

When I click on the default value itself, the expression is fine, but the change dosen't reflect on the drop-down, it still shows every hour in the dropdown

@xrutayisire xrutayisire added bug Something isn't working PR welcome You can open a PR for this issue enhancement New feature or request labels Jun 27, 2024
@xrutayisire
Copy link
Owner

Hi,

I saw two different things in your issue:

  1. [bug] allowEmpty='never' should return an error if cron value equals * * * * *
    Clearly there is a bug here, allowEmpty='never' should never allow * * * * * as a cron value, and should return an error.
    A fix is needed

  2. [enhancement] Add, allowEmpty support in dropdownsConfig
    Today, you would not have been able to do exactly what you want, with or without the bug. If you want to allowEmpty='never' for specifically one dropdown, it's not possible. Also, I see that you may not only want an error returned but a fallback to a default value. That is not supported.

I don't have the time to work on this library these days, but I would be happy to review a PR that fix the bug and add the new feature you would like.

@xrutayisire
Copy link
Owner

Note that dropdownsConfig prop first need a fix to prevent an infinite loop: #67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request PR welcome You can open a PR for this issue
Projects
None yet
Development

No branches or pull requests

2 participants