Default Property Settings

Hope this is not silly question, but I often have a need to change the default setup of some SyncFusion controls. For example, for (nearly) all SfNumericTextBox's set ShowSpinButton=false, or for all SfTextBox, set FloatLabelType=FloatLabelType.Auto.

Key being, I want to change the default behaviour, but rarely, also initialise controls with different behaviour.

Is there a way to set the default property settings for all instances of a control type in a project to be other than SyncFusions's coded defaults.

N.B. I guess I could sub-class a new control, but was hoping there is a better way to change default configuration on a project bases.

Any tips?

Phil


3 Replies

SP Sureshkumar P Syncfusion Team August 12, 2022 11:57 AM UTC

Hi Phil,

We suggest you achieve your requirement by using the custom component rendering. We have prepared the sample based on your requirement.

Find the sample code here:

Parent components:

[textbox components]

@typeparam TVal;

 

<p>component value: @Value</p>

 

<SfTextBox Value="@Value" Placeholder="@CustomPlaceHolder" FloatLabelType="FloatLabelType.Auto" ValueChanged="ValueChanged" ValueExpression="@ValueExpression"></SfTextBox>

 

@code

{

    [Parameter]

 

    public string Value { get; set; }

 

    [Parameter]

 

    public string CustomPlaceHolder { get; set; }

 

    [Parameter]

    public Expression<Func<string>> ValueExpression { get; set; }

 

    [Parameter]

    public EventCallback<string> ValueChanged { get; set; }

   

}

 

[numerictextbox component]

@typeparam TVal;

 

<p>component value: @Value</p>

 

<SfNumericTextBox TValue="TVal" Value="@Value" Placeholder="@CustomPlaceHolder" FloatLabelType="FloatLabelType.Auto" ShowSpinButton="false" ValueChanged="ValueChanged" ValueExpression="@ValueExpression"></SfNumericTextBox>

 

@code

{

    [Parameter]

 

    public TVal Value { get; set; }

 

    [Parameter]

 

    public string CustomPlaceHolder { get; set; }

 

    [Parameter]

    public Expression<Func<TVal>> ValueExpression { get; set; }

 

    [Parameter]

    public EventCallback<TVal> ValueChanged { get; set; }

   

}

 

[Child component]

<span>TextBoxComponent</span>

<CustomTextbox TVal="PersonModel" @bind-Value="Person.Name" CustomPlaceHolder="TextBoxPlaceHolder"></CustomTextbox>

 

 

<span>NumericTextboxComponent</span>

<CustomNumericTextbox TVal="double" @bind-Value="Person.Value" CustomPlaceHolder="NumericTextBoxPlaceHolder"></CustomNumericTextbox>

 

 

@code {

    // validation

    public PersonModel Person = new PersonModel();

 

    public class PersonModel

    {

        public String Name { get; set; }

        public double Value { get; set; }

    }

}

Find the sample in the attachment:

Regards,

Sureshkumar P


Attachment: BlazorAppTest1_3e199014.zip


PH Phil Holmes August 15, 2022 08:41 AM UTC

Thanks Sureshkumar,

Yes, I can see what you're doing there. Wouldn't a derivative like this be a bit simpler & flexible?

using Syncfusion.Blazor.Inputs;



namespace Sirrus.Client.Components {
   public class CTextBox : SfTextBox {


      public new FloatLabelType FloatLabelType = FloatLabelType.Auto;
      public CTextBox() {
         base.FloatLabelType = this.FloatLabelType;
      }


   }


}

Anyway, either way works. I was just asking if there was a way to configure defaults in a project, but can be done this way.

Thanks,

Phil



MM Mohanraj Mathaiyan Syncfusion Team August 16, 2022 04:36 PM UTC

Hi Phil Holmes,


Thank you for sharing your solution. You can use anyone solution as per your choice.


Regards,

Mohanraj M


Loader.
Up arrow icon