I have an 10 field in model class and I have set required field ( mandatory field ) for all validation.
I have used syncfusion control to bind this model.
The validation is working fine as per our requirement using Data Annotation
I would like to know below clarification for validation
I have 10 fields in model class,and I have stored this field in separate table with three login field
For example
Login1
Login2
Login3
Login1:-
Login1 should validate field1 to field4
Login2:-
Login2 should validate field3 to field6
Login3:-
Login3 should validate field7 to field10
Thanks for effort..
The above code is not related to our requirement.
Please see my actual requirement with example.
In above example code , you have created three razor file (login1,login2,login3) and single model class.
But my requirement is single razor file (customer.razor) and single model class with login wise validation
For example :-
In customer.razor file
For login1,email ID is required but phone no is not required
For login2,email ID is not required but phone no is required
For login3, both are required
For login4,both are not required
Note:-
I have maintained (required or not required ) for each field in separate table.
I would like to validate required field based on this condition
Hope it's clear...
|
public class LoginAttribute : ValidationAttribute
{
public string ValidValue { get; set; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var lowerValue = value?.ToString().ToLower();
if (!string.IsNullOrEmpty(lowerValue) && lowerValue.Equals(ValidValue.ToLower()))
return null;
return new ValidationResult(ErrorMessage, new[] { validationContext.MemberName });
}
}
public class FormData
{
[LoginAttribute(ErrorMessage ="Enter valid message", ValidValue = "User1")]
public string Field1 { get; set; }
|
Thanks for reply
Is it possible to visible synfussion control true or false based on above scenario
|
<div>
<label for="Name" style="padding: 20px 0 5px 0">Field1</label>
<SfTextBox id='textbox' @bind-Value="@model.Field1" Placeholder="Enter a Field1"></SfTextBox>
<ValidationMessage For="@(() => model.Field1)" />
</div>
@if(model.Field1 != null && model.Field1 == "User1")
{
<div>
<label for="Name" style="padding: 20px 0 5px 0">Field2</label>
<SfTextBox id='textbox' @bind-Value="@model.Field2" Placeholder="Enter a Field2"></SfTextBox>
<ValidationMessage For="@(() => model.Field2)" />
</div>
} |
I have one more clarification
How can I add css class for required field (* which should be in red color) as per above code.
|
<div>
<label for="Name" style="padding: 20px 0 5px 0" class="required">Field3</label>
<SfTextBox id='textbox' @bind-Value="@model.Field3" Placeholder="Enter a Field3"></SfTextBox>
<ValidationMessage For="@(() => model.Field3)" />
</div>
<div>
<label for="Name" style="padding: 20px 0 5px 0" class="required">Field4</label>
<SfTextBox id='textbox' @bind-Value="@model.Field4" Placeholder="Enter a Field3"></SfTextBox>
<ValidationMessage For="@(() => model.Field4)" />
</div>
<style>
.required:after {
content:"*";
color: red;
}
</style> |
pls help
Thanks for reply...
Is it possible to change color of placeholder if it is mandatory instead of *.??
Pls help
|
<EditForm Model="@model" OnValidSubmit="@OnValidSubmit">
<DataAnnotationsValidator />
<div>
<label for="Name" style="padding: 20px 0 5px 0">Field1</label>
<SfTextBox id='textbox' @bind-Value="@model.Field1" Placeholder="Enter a Field1"></SfTextBox>
<ValidationMessage For="@(() => model.Field1)" />
</div>
@if(model.Field1 != null && model.Field1 == "User1")
{
<div>
<label for="Name" style="padding: 20px 0 5px 0" class="required">Field2</label>
<SfTextBox id='textbox' @bind-Value="@model.Field2" Placeholder="Enter a Field2"></SfTextBox>
<ValidationMessage For="@(() => model.Field2)" />
</div>
}
<div>
<label for="Name" style="padding: 20px 0 5px 0" class="required">Field3</label>
<SfTextBox id='textbox' @bind-Value="@model.Field3" CssClass="requiredClass" Placeholder="Enter a Field3"></SfTextBox>
<ValidationMessage For="@(() => model.Field3)" />
</div>
<div>
<label for="Name" style="padding: 20px 0 5px 0" class="required">Field4</label>
<SfTextBox id='textbox' @bind-Value="@model.Field4" CssClass="requiredClass" Placeholder="Enter a Field4"></SfTextBox>
<ValidationMessage For="@(() => model.Field4)" />
</div>
<div class="sfButton">
<SfButton type="submit" IsPrimary="true">Submit</SfButton>
</div>
</EditForm>
<style>
.sfButton {
padding-top: 10px;
display: flex;
justify-content: center;
}
.required:after {
content:"*";
color: red;
}
.requiredClass.e-input-group input.e-input::-webkit-input-placeholder {
color: red;
}
</style> |
I have another clarification.
Can I add "*" required class in "Place Holder" instead of using Label
<label for="Name" style="padding: 20px 0 5px 0" class="required">Field4</label>
|
@using Syncfusion.Blazor.Inputs
<SfTextBox FloatLabelType="FloatLabelType.Auto" Placeholder="Enter a Field" ></SfTextBox>
<style>
.e-input-group.e-control-wrapper.e-float-input .e-float-text::after {
content: "*";
color: red;
}
</style>
|