iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hello,I’m having trouble getting a UXTextBox to show validation errors with the red outline and default call outI have an entity on the server side (using EF 4.1 Code First)class WebAccess{[Email] public string Email { get; set; }}class User{// this one is required by default because it’s a complex typepublic WebAccess WebAccess { get; set; }}EmailAttribute is a custom validation attribute. I’ve validated it works and that it gets copied over to the server.In the view, I set the DataContext:<ui:UXPage.DataContext> <ViewModels:SuperAdministratorViewModel /> </ui:UXPage.DataContext>And then:<ui:UXItemsControl DataContext="{Binding NewAdministrator}" ItemContainerStyle="{StaticResource FieldLabelStyle}"><ui:FieldLabel Header="Email" Style="{StaticResource RequiredFieldLabelStyle}"> <ui:UXTextBox Style="{StaticResource SimpleTextBoxStyle}" Text="{Binding Path=WebAccess.Email, Mode=TwoWay, ValidatesOnDataErrors=True}" ui:DataBinding.ClearErrorOnTextInput="True" /> </ui:FieldLabel> </ui:UXItemsControl>However, when I type and move the focus to another control, the validation won’t show at allWhat am I missing here?ThanksGeorgios
Yudi,
I have seen the code you're referring to in one of your samples.
However, it's largely irrelevant - I am using the Entity Framework for persistence as I've indiciated in my original post.
The true example of how to do validation is in the ClientUI SL Business App with RIA SP1 template.
I finally figured out that it wasn't working because I hadn't assigned an error string in my validation attribute - it should have a default one but well, it doesn't.
Georgios
Following is the list that needs to be added in order to perform validation:
public bool EnableValidation { get; set; }
public double Price { get { return _price; } set { if (_price != value) { _price = value; ClearError("Price"); if (EnableValidation && double.IsNaN(this.Price) || this.Price == 0.0) SetError("Price", "Price is required"); OnPropertyChanged("Price"); } } }
using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace ValidationOnTextInput.ViewModels { public class ValidationViewModelBase : ViewModelBase, IDataErrorInfo { #region Properties private Dictionary<string, string> _errors = new Dictionary<string, string>(); public virtual bool HasErrors { get { return _errors.Count > 0; } } #endregion #region Public public void SetError(string propertyName, string errorMessage) { _errors[propertyName] = errorMessage; this.OnPropertyChanged(propertyName); } #endregion #region Protected protected void ClearError(string propertyName) { this._errors.Remove(propertyName); } protected void ClearAllErrors() { List<string> properties = new List<string>(); foreach (KeyValuePair<string, string> error in this._errors) properties.Add(error.Key); this._errors.Clear(); foreach (string property in properties) this.OnPropertyChanged(property); } #endregion #region IDataErrorInfo Members public string Error { get { if (this.HasErrors) return this._errors.First().Value; return null; } } public string this[string columnName] { get { if (this._errors.ContainsKey(columnName)) { return this._errors[columnName]; } return string.Empty; } } #endregion } }
using [ProjectName].Models; namespace [ProjectName].ViewModels { public class SomeViewModel : ValidationViewModelBase { // Constructor public SomeViewModel() { } } }
<Intersoft:UXTextBox HorizontalAlignment="Center" Width="60" Text="{Binding Book.Price, Mode=TwoWay, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, StringFormat=\{0:c\}}" Intersoft:DataBinding.ClearErrorOnTextInput="True"/>
I enclosed a working simple sample of Model; ViewModel; and View for reference as attachment.
Hope this helps.
Glad to hear the good news.
Should you need further assistance or run into any problems regarding our controls, feel free to post it into our forum. We would be happy to assist you again.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname