Validation [Required] with tag

Topics: Feature requests, Questions
Apr 3, 2014 at 9:49 AM
Edited Apr 3, 2014 at 10:35 AM
Hello

Whats the simplest way to disable button with command when a required field is empty.

Add a IValidationSummary Property. Override ValidateFields. CreateCommand with CommandHelper with the IValidationSummary as argument.

(and sorry it bothers me if all required fields are filled at startup but the the button is still disabled because, the ValidationSummary is null )

Maybe a Required Attribute with tag help. To map to the ValidationSummary so it is not necessary to override ValidateFields.

Or any other solution?
Coordinator
Apr 3, 2014 at 10:05 PM
I have absolutely no idea what you are saying. You can use the CanExecute to determine whether a command can be executed or not. Then you can check for validations of a specific field in the ValidationContext.
Apr 4, 2014 at 6:55 AM
Sorry.

Little Example:
MyCommand = CommandHelper.CreateCommand(MyExecute, () => MyValidationSummary);

[ValidationToViewModel(Tag = "MyTag")]
public IValidationSummary MyValidationSummary { get; set; }

public string Name
{
      get { return GetValue<string>(NameProperty); }
      set { SetValue(NameProperty, value); }
}

public static readonly PropertyData NameProperty = RegisterProperty("Name", typeof (string));

protected override void ValidateFields(List<IFieldValidationResult> validationResults)
{
    if (string.IsNullOrEmpty(Name))
    {
        validationResults.Add(FieldValidationResult.CreateErrorWithTag(NameProperty, "Field Name is required", "MyTag"));  
    }
}
here is also my other problem -> MyValidationSummary is null at startup if Name is filled at startup. No error -> no Validation summary -> and Button is disabled :-( this example you can see in my linked isue.

But my question here is how to disable Button ( better MyCommand ) if Property Name is decorated with [Required] Attribute instead the ValidateFields method.

Little bit more clear?
Apr 4, 2014 at 8:35 AM
Also tried this for test (-> without "tags")
[Required(AllowEmptyStrings = false)]
public string Name
{
      get { return GetValue<string>(NameProperty); }
      set { SetValue(NameProperty, value); }
}

public static readonly PropertyData NameProperty = RegisterProperty("Name", typeof (string));

CanExecute()
{
    return !ValidationContext.HasErrors;
}
Name is null. No matter ValidationContext.HasErrors returns false ??

Whats wrong?
Apr 7, 2014 at 10:29 AM
Is the question still not clear?
Coordinator
Apr 10, 2014 at 7:26 PM
I think it is clear. Will look at it when I have time (and that is not going to be soon).