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

Ignore editForm api key validation? #2280

Closed
PhilipeGatis opened this issue Jan 16, 2020 · 6 comments
Closed

Ignore editForm api key validation? #2280

PhilipeGatis opened this issue Jan 16, 2020 · 6 comments

Comments

@PhilipeGatis
Copy link
Contributor

PhilipeGatis commented Jan 16, 2020

Hi,
I`d like to ignore validation in "API" tab on field "KEY" on editForm.
Have some way?
I tried this way but not worked!

const options = {
  builder: {
    data: false,
    premium: false,
  },
  editForm: {
    textfield: [
      {
        key: 'api',
        ignore: false,
        components: [
          {
            key: 'key',
            validate: false
          }
        ]
      }
    ]
  }
};
@PhilipeGatis PhilipeGatis changed the title Override editForm api key validation? Ignore editForm api key validation? Jan 16, 2020
@randallknutson
Copy link
Contributor

I believe validate is an object. Have you tried setting it to validate: {}? That might work. Be aware though that the key is the most important field on the component definition as it controls where the value will be saved in the submission. If you don't make it required, weird things might start happening.

@PhilipeGatis
Copy link
Contributor Author

PhilipeGatis commented Jan 16, 2020

Yes, its an object.
I tried with object below and it didn't work...

const options = {
  builder: {
    data: false,
    premium: false,
  },
  editForm: {
    textfield: [
      {
        key: 'api',
        ignore: false,
        components: [
          {
            key: 'key',
            validate: {
              pattern: ''
            }
          }
        ]
      }
    ]
  }
};

I debbuged in chrome and the object is not overrided :(
image

@randallknutson
Copy link
Contributor

That looks like it should work the way you wrote it. It might be that the merge function isn't catching it correctly. Can you track through the code right above your screenshot to see if the merge is not working correctly?

If that doesn't work, we can get you on a support package and have some support resources for you.

@PhilipeGatis
Copy link
Contributor Author

PhilipeGatis commented Jan 17, 2020

@randallknutson
I found the problem!
On function "unify Components" has an if clause where is verified two objects has the same property, if they have, don't merge.

https://github.com/formio/formio.js/blob/master/src/components/_classes/component/editForm/utils.js#L7 -> function
https://github.com/formio/formio.js/blob/master/src/components/_classes/component/editForm/utils.js#L15 -> first if clause
https://github.com/formio/formio.js/blob/master/src/components/_classes/component/editForm/utils.js#L20 -> second if clause

unifyComponents: function unifyComponents(objValue, srcValue) {
    if (objValue.key && srcValue.key) {
      if (objValue.skipMerge || srcValue.skipMerge) {
        return false;
      }

      if (objValue.label === 'pudim') {
        debugger
      }

      if (objValue.key === srcValue.key) {
        // Create complete objects by including missing keys.
        _lodash.default.each(objValue, function (value, prop) {
          if (!srcValue.hasOwnProperty(prop)) {
            srcValue[prop] = value;
          }
        });

        _lodash.default.each(srcValue, function (value, prop) {
          if (!objValue.hasOwnProperty(prop)) {
            objValue[prop] = value;
          }
        });

        if (objValue.components) {
          srcValue.components = EditFormUtils.sortAndFilterComponents(_lodash.default.unionWith(objValue.components, srcValue.components, EditFormUtils.unifyComponents));
        }

        return true;
      } else {
        return false;
      }
    }

    return _lodash.default.isEqual(objValue, srcValue);
  }

@randallknutson
Copy link
Contributor

Can you make a recommendation for the change? I kind of see what is going wrong here but I'm not clear on what should fix it.

@Feargalicious
Copy link

Recommend closing this issue, due to PR #2412 adding this functionality. I used it to override the tooltip, thanks!


const options = {
  builder: {
    data: false,
    premium: false,
  },
  editForm: {
    textfield: [
      {
        key: 'api',
        ignore: false,
        components: [
          {
            key: 'key',
            overrideEditForm: true,
            tooltip: 'Super vague tooltip clients understand'
          }
        ]
      }
    ]
  }
};

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

4 participants