Hi @manish-sharma we used the code and made it a function, and it is working fine but I am facing a challenge with a component
Builder.registerComponent(EditorialGridBuilder, {
name: 'EditorialGrid',
inputs: [
{
name: 'editorialType',
type: 'string',
defaultValue: 'Story',
enum: ['Story', 'EditorialCardUsp'],
required: true,
},
{
name: 'EditorialCardProps',
type: 'object',
subFields: [
{
name: 'title',
type: 'string',
defaultValue: 'Stories from Ama',
required: false,
},
{
name: 'description',
type: 'richText',
required: false,
},
{
name: 'buttonText',
type: 'string',
defaultValue: 'See all stories',
required: false,
helperText: 'Text for the button. Leave empty to hide the button.',
},
// Button URL fields - using helpers
...urlFieldGroup({
urlTypeFieldName: 'buttonUrlType',
manualFieldName: 'buttonManualUrl',
internalFieldName: 'buttonInternalUrl',
}),
{
name: 'cards',
type: 'list',
subFields: [
imageField({
fieldName: 'Image',
required: true,
allowedTypes: ['.jpg', '.jpeg', '.png', '.webp'],
includeAltText: true,
altTextDefault: 'Editorial image',
}),
{
name: 'title',
type: 'string',
required: false,
helperText: 'length should be between 40-90 characters',
onChange: characterValidationHandler({
//minLength: 40,
maxLength: 90,
fieldName: 'title',
fieldType: 'string',
}),
// onChange: (options) => {
// const editorialType = options.get('editorialType');
// const titleValue = options.get('title');
// if (editorialType === 'Story') {
// return characterValidationHandler({
// //minLength: 40,
// maxLength: 90,
// fieldName: 'title',
// fieldType: 'string',
// })(titleValue);
// }
// if (editorialType === 'EditorialCardUsp') {
// return characterValidationHandler({
// //minLength: 5,
// maxLength: 22,
// fieldName: 'title',
// fieldType: 'string',
// })(titleValue);
// }
// return true;
// },
},
{
name: 'description',
type: 'richText',
required: true,
helperText: 'length should be between 400-500 characters',
onChange: characterValidationHandler({
//minLength: 400,
maxLength: 500,
fieldName: 'description',
fieldType: 'richText',
}),
},
{
name: 'tags',
type: 'string',
defaultValue: '',
required: false,
helperText: 'Comma-separated list of tags (e.g., "Insider guides, Life Onboard")',
},
...urlFieldGroup({
manualFieldName: 'manualUrl',
internalFieldName: 'cardurl',
manualHelperText:
'Enter a full URL (e.g., https://...) or internal path (/stories/article-1).',
}),
],
},
],
defaultValue: EditorialCardData,
},
],
});
As you can see we are using a field “name: ‘editorialType’,” , and based on this showing different UI variant of a component.
In this component title field we want the limits to be different based on “editorialType” but unable to do so cause no if else is working even the editorialType is not accessible within this block we can’t get its value the function “characterValidationHandler” is the function implementation for your provided code which takes the max length value. can you help us with that please.