survey-creator icon indicating copy to clipboard operation
survey-creator copied to clipboard

Unable to hide maskSettings items when creating a Specialized Question type

Open doelgonzo opened this issue 1 year ago • 2 comments

Are you requesting a feature, reporting a bug or ask a question?

Bug/Question

What is the current behavior?

The documentation here indicates that End users cannot break the functionality because the Property Grid hides the questionJSON object properties., but when I set some of these properties they still appear in the property grid (see test code). It's possible I'm doing something wrong, but I understand it that this should work this way. My gut says it's related to these being nested values, but I don't know how to get around it.

I also tried:

inheritBaseProps: ["maskSettings:max","maskSettings:min","maskSettings:decimalSeparator","maskSettings:thousandsSeparator", "maskSettings:allowNegativeValues"]

and it made no difference. Any guidance is welcome. Also, the console.log below prints out base properties but none of the maskSettings-related ones...

What is the expected behavior?

They are hidden, or I have a programatic way to hide these properties.

How would you reproduce the current behavior (if this is a bug)?

Provide the test code and the tested page URL (if applicable)

Test code

export const registerNumberInput = () => {
   const existingQuestion = ComponentCollection.Instance.getCustomQuestionByName(
    CustomField.NumberInput
  );

  // Register the NumericInput model with the ElementFactory
  if (!existingQuestion) {
    ComponentCollection.Instance.add({
      name: CustomField.NumberInput,
      iconName: CustomField.NumberInput,
      title: "Number Input",
      questionJSON: {
        type: "text",
        inputType: "text",
        maskType: "numeric",
        maskSettings: {
          saveMaskedValue: false,
          precision: 0,
        },
      },
      inheritBaseProps: ["maskSettings"],
    });
  }

  console.log(
    ComponentCollection.Instance.getCustomQuestionByName(
      CustomField.NumberInput
    )
  );
};

Specify your

  • browser:
  • editor version: 1.11.13

doelgonzo avatar Aug 30 '24 21:08 doelgonzo

Hello, You set inheritBaseProps: ["maskSettings"], therefore, Mask Settings appear in a property grid. If you wish to define mask settings but make them unavailable in a property grid, update your specialized question definition and remove the inheritBaseProps attribute.

 ComponentCollection.Instance.add({
      name: "custom-number-input",
      title: "Number Input",
      questionJSON: {
        type: "text",
        inputType: "text",
        maskType: "numeric",
        maskSettings: {
          saveMaskedValue: false,
          precision: 0,
        },
      }
});

Let me know if you have any questions.

JaneSjs avatar Sep 05 '24 16:09 JaneSjs

@JaneSjs Is there a way to make maskSettings.saveMaskedValue or maskSettings.precision not appear on on the property grid but have the others within maskSettings still appear?

doelgonzo avatar Sep 06 '24 14:09 doelgonzo

Hello @doelgonzo, Please accept my apologies for the delayed response. Use the creator.onShowingProperty function to hide the saveMaskedValue and precision mask settings. Consider the following demo: View Plunker.

import { ComponentCollection } from "survey-core";

ComponentCollection.Instance.add({
      name: "number-input",
      title: "Number Input",
      questionJSON: {
        type: "text",
        inputType: "text",
        maskType: "numeric",
        maskSettings: {
          saveMaskedValue: false,
        },
      },
      inheritBaseProps: ["maskSettings"],
});
const propertyStopList = [ "precision", "saveMaskedValue"];

creator.onShowingProperty.add((sender, options) => {
      if(options.obj.getType() === "numericmask" && !!options.parentObj && options.parentObj.getType() === "number-input" && propertyStopList.indexOf(options.property.name) >= 0){         
        options.canShow = false;
      }
});

Feel free to reactivate this thread if you require further assistance.

JaneSjs avatar Nov 28 '24 08:11 JaneSjs