How to replace default validation error message in PDP page by using extension.

Here replacing default data validation error message from source code by using new extension …

PDP extension entry file

_.extend(ProductOptionModel.prototype, {
                    validation: {
                        'value.internalid': {
                            fn: function optionValueValidator() {
                                const value = this.get('value') && this.get('value').internalid;
                
                                if (this.get('isMandatory') && !value) {
                                    return ('Please select a color');
                                }
                                if (value) {
                                    const max_length = 160;
                
                                    if (this.get('type') === 'text' || this.get('type') === 'textarea') {
                                        if (
                                            this.get('isMandatory') &&
                                            (!String(value).trim() || value.length > max_length)
                                        ) {
                                            return Utils.translate('Please enter a valid input for this string');
                                        }
                                        if (value.length > max_length) {
                                            return Utils.translate(
                                                'Please enter a string shorter (maximum length: $(0))',
                                                max_length
                                            );
                                        }
                                    } else if (
                                        this.get('type') === 'email' &&
                                        !Backbone.Validation.patterns.email.test(value)
                                    ) {
                                        return Utils.translate('Please enter a valid email');
                                    } else if (
                                        this.get('type') === 'integer' &&
                                        !Backbone.Validation.patterns.netsuiteInteger.test(value)
                                    ) {
                                        return Utils.translate('Please enter a valid integer number');
                                    } else if (
                                        this.get('type') === 'float' &&
                                        !Backbone.Validation.patterns.netsuiteFloat.test(value)
                                    ) {
                                        return Utils.translate('Please enter a valid decimal number');
                                    } else if (
                                        this.get('type') === 'currency' &&
                                        !Backbone.Validation.patterns.netsuiteFloat.test(value)
                                    ) {
                                        return Utils.translate('Please enter a valid currency number');
                                    } else if (
                                        this.get('type') === 'phone' &&
                                        !Backbone.Validation.patterns.netsuitePhone.test(value)
                                    ) {
                                        return Utils.translate('Please enter a valid phone');
                                    } else if (
                                        this.get('type') === 'percent' &&
                                        !Backbone.Validation.patterns.netsuitePercent.test(value)
                                    ) {
                                        return Utils.translate('Please enter a valid percent');
                                    } else if (
                                        this.get('type') === 'url' &&
                                        !Backbone.Validation.patterns.netsuiteUrl.test(value)
                                    ) {
                                        return Utils.translate('Please enter a valid url');
                                    } else if (
                                        this.get('type') === 'select' &&
                                        !_.findWhere(this.get('values'), { internalid: value })
                                    ) {
                                        return Utils.translate('Please select a valid value for this option');
                                    }
                                }
                            }
                        }
                    }
                });

Leave a comment

Your email address will not be published. Required fields are marked *