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

Add support for RegExp in calculation field array definition #21

Merged
merged 1 commit into from
Dec 13, 2018

Conversation

zimme
Copy link
Contributor

@zimme zimme commented Jul 2, 2018

I'll add tests when you've decided if you want this or not.

Here's an example of working code with this PR.

createDecorator({
  {
      field: [
        `data[${index}].salesValue`,
        `data[${index}].totalOtherCosts`,
        `data[${index}].totalInvoiceCost`,
        new RegExp(`^data\\[${index}\\]\\.orderMethods\\[\\d+\\]\\.totalCost$`), // This will now work
        new RegExp(
          `^data\\[${index}\\]\\.goodsProcessing\\[\\d+\\]\\.totalCost$`,
        ),
      ],
      updates: {
        [`data[${index}].grandTotal`]: (_ignored, values) => {
          ...

@zimme zimme changed the title Add support for RegExp in calculatoin field definition Add support for RegExp in calculation field definition Jul 2, 2018
@codecov
Copy link

codecov bot commented Jul 2, 2018

Codecov Report

Merging #21 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #21   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines          37     38    +1     
  Branches       12     14    +2     
=====================================
+ Hits           37     38    +1
Impacted Files Coverage Δ
src/decorator.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f987ee...dab00f8. Read the comment docs.

@zimme zimme changed the title Add support for RegExp in calculation field definition Add support for RegExp in calculation field array definition Jul 2, 2018
@altwohill
Copy link

altwohill commented Jul 13, 2018

You can already do this.

const decorator = createDecorator({
    field: /^((?!Agree|Privacy).)*$/,  // <--- this regex picks everything except "Agree' and "Privacy"
    updates: async (value, name, allValues) => {...}
});

@zimme
Copy link
Contributor Author

zimme commented Jul 13, 2018

Yes but currently you can only specify field as RegExp or String or Array of String. This also allows Array of String or RegExp.

@erikras erikras merged commit bac6a75 into final-form:master Dec 13, 2018
@erikras
Copy link
Member

erikras commented Dec 13, 2018

Sorry. Can you please add the tests in another PR?

@erikras
Copy link
Member

erikras commented Dec 13, 2018

Published in v1.3.0.

@zimme
Copy link
Contributor Author

zimme commented Dec 13, 2018

Awesome! I'll try and get to the tests if I get some me time during the holidays, but i dont count on it as i recently got a baby 👶

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

Successfully merging this pull request may close these issues.

3 participants