Skip to content

Commit

Permalink
Rating Scale - Cannot override a default Value for the displayMode pr…
Browse files Browse the repository at this point in the history
…operty (#7345)

* work for #7332 Rating Scale - Cannot override a default Value for the displayMode property

* work for #7332 hide console.error

---------

Co-authored-by: OlgaLarina <olga.larina.dev@gmail.com>
  • Loading branch information
OlgaLarina and OlgaLarina committed Nov 14, 2023
1 parent 9347c59 commit 4bdd5d5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/console-warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ export class ConsoleWarnings {
// eslint-disable-next-line no-console
console.warn(text);
}
public static error(text: string): void {
// eslint-disable-next-line no-console
console.error(text);
}
}
5 changes: 5 additions & 0 deletions src/jsonobject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { surveyLocalization } from "./surveyStrings";
import { Base, ComputedUpdater } from "./base";
import { Helpers, HashTable } from "./helpers";
import { ConsoleWarnings } from "./console-warnings";

export interface IPropertyDecoratorOptions<T = any> {
defaultValue?: T;
Expand Down Expand Up @@ -67,6 +68,10 @@ export function property(options: IPropertyDecoratorOptions = {}) {
if (!options || !options.localizable) {
Object.defineProperty(target, key, {
get: function () {
// const serializationProperty = Serializer.getProperty(target.getType(), key);
// if(!!serializationProperty && options.defaultValue !== undefined) {
// ConsoleWarnings.error("remove defaultValue from @property for class " + target.getType() + " property name is " + key);
// }
let defaultVal = null;
if (!!options) {
if (typeof options.getDefaultValue === "function") {
Expand Down
2 changes: 1 addition & 1 deletion src/martixBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class QuestionMatrixBaseModel<TRow, TColumn> extends Question {
/**
* Aligns matrix cell content in the vertical direction.
*/
@property({ defaultValue: "middle" }) verticalAlign: "top" | "middle";
@property() verticalAlign: "top" | "middle";

/**
* Specifies whether to apply shading to alternate matrix rows.
Expand Down
2 changes: 1 addition & 1 deletion src/question_dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class QuestionDropdownModel extends QuestionSelectBase {
* @see choicesLazyLoadEnabled
* @see SurveyModel.onChoicesLazyLoad
*/
@property({ defaultValue: 25 }) choicesLazyLoadPageSize: number;
@property() choicesLazyLoadPageSize: number;

public getControlClass(): string {
return new CssClassBuilder()
Expand Down
14 changes: 7 additions & 7 deletions src/question_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class QuestionRatingModel extends Question {
return !this.readOnly && this.visibleRateValues.filter(v => v.value == this.value)[0]?.locText;
}

@property({ defaultValue: true }) autoGenerate: boolean;
@property() autoGenerate: boolean;

/**
* A list of rate values.
Expand Down Expand Up @@ -264,7 +264,7 @@ export class QuestionRatingModel extends Question {
*
* [View Demo](https://surveyjs.io/form-library/examples/rating-scale/ (linkStyle))
*/
@property({ defaultValue: 5 }) rateCount: number;
@property() rateCount: number;

private static colorsCalculated: boolean = false;

Expand Down Expand Up @@ -454,7 +454,7 @@ export class QuestionRatingModel extends Question {
* @see rateMax
* @see rateValues
*/
@property({ defaultValue: false }) displayRateDescriptionsAsExtremeItems: boolean;
@property() displayRateDescriptionsAsExtremeItems: boolean;

/**
* Specifies whether to display rate values as buttons or items in a drop-down list.
Expand All @@ -469,7 +469,7 @@ export class QuestionRatingModel extends Question {
* @see rateType
*/
@property({
defaultValue: "auto", onSet: (val: string, target: QuestionRatingModel) => {
onSet: (val: string, target: QuestionRatingModel) => {
if (!target.isDesignMode) {
if (val === "dropdown") {
target.renderAs = "dropdown";
Expand All @@ -494,7 +494,7 @@ export class QuestionRatingModel extends Question {
* @see rateColorMode
* @see displayMode
*/
@property({ defaultValue: "labels" }) rateType: "labels" | "stars" | "smileys";
@property() rateType: "labels" | "stars" | "smileys";

public get rateDisplayMode() {
return this.rateType;
Expand All @@ -513,7 +513,7 @@ export class QuestionRatingModel extends Question {
* [View Demo](https://surveyjs.io/form-library/examples/rating-scale/ (linkStyle))
* @see rateColorMode
*/
@property({ defaultValue: "monochrome" }) scaleColorMode: "monochrome" | "colored";
@property() scaleColorMode: "monochrome" | "colored";
/**
* Specifies how to colorize the selected emoji. Applies only if [`rateType`](https://surveyjs.io/form-library/documentation/api-reference/rating-scale-question-model#rateType) is `"smileys"`.
*
Expand All @@ -523,7 +523,7 @@ export class QuestionRatingModel extends Question {
* - `"scale"` (default) - Inherits the color from the scale.
* @see scaleColorMode
*/
@property({ defaultValue: "scale" }) rateColorMode: "default" | "scale";
@property() rateColorMode: "default" | "scale";

public get isStar() {
return this.rateType == "stars";
Expand Down
6 changes: 3 additions & 3 deletions src/question_signaturepad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,19 @@ export class QuestionSignaturePadModel extends Question {
*
* > The signature area is scaled only for display. The resulting image will have dimensions specified by the [`signatureHeight`](#signatureHeight) and [`signatureWidth`](#signatureWidth) properties.
*/
@property({ defaultValue: false }) signatureAutoScaleEnabled: boolean;
@property() signatureAutoScaleEnabled: boolean;
/**
* Speicifies the minimum width of pen strokes, measured in pixels.
*
* Default value: 0.5
*/
@property({ defaultValue: 0.5 }) penMinWidth: number;
@property() penMinWidth: number;
/**
* Speicifies the maximum width of pen strokes, measured in pixels.
*
* Default value: 2.5
*/
@property({ defaultValue: 2.5 }) penMaxWidth: number;
@property() penMaxWidth: number;

private get containerHeight(): any {
return this.signatureHeight || defaultHeight;
Expand Down
3 changes: 1 addition & 2 deletions src/question_tagbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class QuestionTagboxModel extends QuestionCheckboxModel {
* Specifies whether users can enter a value into the input field to filter the drop-down list.
*/
@property({
defaultValue: true,
onSet: (newValue: boolean, target: QuestionTagboxModel) => {
if (!!target.dropdownListModel) {
target.dropdownListModel.setSearchEnabled(newValue);
Expand Down Expand Up @@ -84,7 +83,7 @@ export class QuestionTagboxModel extends QuestionCheckboxModel {
* @see choicesLazyLoadEnabled
* @see SurveyModel.onChoicesLazyLoad
*/
@property({ defaultValue: 25 }) choicesLazyLoadPageSize: number;
@property() choicesLazyLoadPageSize: number;
/**
* Specifies whether to close the drop-down menu after a user selects a value.
*/
Expand Down

0 comments on commit 4bdd5d5

Please sign in to comment.