/// <summary> /// Render TextInput view component. /// </summary> /// <param name="aspFor"></param> /// <param name="label"></param> /// <param name="populateWithCurrentValue"></param> /// <param name="type"></param> /// <param name="spellCheck"></param> /// <param name="hintText">Leave blank for no hint.</param> /// <param name="autocomplete">Leave blank to set no autocomplete on the input element.</param> /// <param name="cssClass"></param> /// <returns></returns> public IViewComponentResult Invoke( string aspFor, string label, bool populateWithCurrentValue, string type, bool spellCheck, string hintText, string autocomplete, string cssClass ) { var model = ViewData.Model; var property = model.GetType().GetProperty(aspFor); var valueToSet = populateWithCurrentValue ? property?.GetValue(model)?.ToString() : null; var errorMessages = ViewData.ModelState[property?.Name]?.Errors.Select(e => e.ErrorMessage) ?? new string[] { }; var textBoxViewModel = new TextInputViewModel( aspFor, aspFor, label, valueToSet, type, spellCheck, string.IsNullOrEmpty(autocomplete) ? null : autocomplete, errorMessages, string.IsNullOrEmpty(cssClass) ? null : cssClass, string.IsNullOrEmpty(hintText) ? null : hintText ); return(View(textBoxViewModel)); }
public TextInputWindow(string title, string prompt, string defaultText, bool isMandatory) { InitializeComponent(); Title = title; textInputViewModel = new TextInputViewModel(prompt, defaultText, isMandatory, OnEnd); DataContext = textInputViewModel; }
internal static IHtmlContent GenerateHtml <TModel, TProperty>( IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > propertyLambdaExpression, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null, string classes = null, TextInputAppendixViewModel textInputAppendix = null, string type = "text", string autocomplete = null ) where TModel : GovUkViewModel { PropertyInfo property = ExpressionHelpers.GetPropertyFromExpression(propertyLambdaExpression); string propertyName = property.Name; TModel model = htmlHelper.ViewData.Model; string currentValue = ExtensionHelpers.GetCurrentValue(model, property, propertyLambdaExpression); string id = $"GovUk_{propertyName}"; if (labelOptions != null) { labelOptions.For = id; } var textInputViewModel = new TextInputViewModel { Name = $"GovUk_Text_{propertyName}", Id = id, Value = currentValue, Label = labelOptions, Hint = hintOptions, FormGroup = formGroupOptions, Classes = classes, TextInputAppendix = textInputAppendix, Type = type, Attributes = new Dictionary <string, string> { { "autocomplete", autocomplete } } }; if (model.HasErrorFor(property)) { textInputViewModel.ErrorMessage = new ErrorMessageViewModel { Text = model.GetErrorFor(property) }; } return(htmlHelper.Partial("/GovUkDesignSystemComponents/TextInput.cshtml", textInputViewModel)); }
public SaveExecuteDialogViewModel( ViewModelEvents viewModelEvents, string buttonText, ETIC2Model etic2Model, SelectionItemType selectionItemType) : base(viewModelEvents, buttonText) { this.textInputViewModel = new TextInputViewModel(viewModelEvents, "Entry: ", string.Empty); this.etic2Model = etic2Model; this.selectionItemType = selectionItemType; this.viewModelEvents = viewModelEvents; }
internal async Task <(ContentDialogResult dialogResult, string name)> GetNewProjectName() { var template = App.CurrentMainPage.Resources["TextInputContent"] as DataTemplate; var inputViewModel = new TextInputViewModel { Question = "Enter name for new Project." }; (ContentDialogResult dialogResult, string name)result = default; var contentControl = new ContentControl { DataContext = inputViewModel, ContentTemplate = template }; var dialog = new ContentDialog { DataContext = inputViewModel, Title = "New Project", Content = contentControl, CloseButtonText = "Cancel", CloseButtonCommand = new RelayCommand(() => { result.dialogResult = ContentDialogResult.Secondary; }), DefaultButton = ContentDialogButton.Primary, PrimaryButtonText = "Create" }; var binding = new Binding { Path = new PropertyPath(nameof(TextInputViewModel.Answer)), Mode = BindingMode.OneWay }; typeof(Binding).GetProperty("DataContext").SetValue(binding, inputViewModel); dialog.SetBinding(ContentDialog.PrimaryButtonCommandParameterProperty, binding); dialog.PrimaryButtonCommand = new RelayCommand <string>(answer => { if (!string.IsNullOrWhiteSpace(answer)) { result.dialogResult = ContentDialogResult.Primary; result.name = answer; dialog.Hide(); } }, answer => !string.IsNullOrWhiteSpace(answer)); await dialog.ShowAsync(); return(result); }
public EditExecuteDialogViewModel( ViewModelEvents viewModelEvents, string buttonText, ETIC2Model etic2Model, SelectionItemType selectionItemType, string selectedItem) : base(viewModelEvents, buttonText) { this.SelectedItem = selectedItem; this.textInputViewModelSelectedItem = new TextInputViewModel(viewModelEvents, "Item name: ", selectedItem); this.etic2Model = etic2Model; this.selectionItemType = selectionItemType; this.viewModelEvents = viewModelEvents; }
public SaveExecuteDoubleDialogViewModel( ViewModelEvents viewModelEvents, string buttonText, ETIC2Model etic2Model, string label1, string label2, string textInput1, string textInput2) : base(viewModelEvents, buttonText) { this.viewModelEvents = viewModelEvents; this.etic2Model = etic2Model; this.textInputViewModel1 = new TextInputViewModel(viewModelEvents, label1, textInput1); this.textInputViewModel2 = new TextInputViewModel(viewModelEvents, label2, textInput2); }
public DeleteExecuteDialogViewModel( ViewModelEvents viewModelEvents, string buttonText, ETIC2Model etic2Model, SelectionItemType selectionItemType, string selectedItem) : base(viewModelEvents, buttonText) { this.textInputViewModelSelectedItem = new TextInputViewModel(viewModelEvents, "Item name: ", selectedItem); this.textInputViewModelSelectedItem.IsReadOnly = true; this.etic2Model = etic2Model; this.selectionItemType = selectionItemType; this.viewModelEvents = viewModelEvents; this.resultDeleteOperation = string.Empty; }
internal static IHtmlContent GenerateHtml <TModel, TProperty>( IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > propertyLambdaExpression, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null, string classes = null, TextInputAppendixViewModel textInputAppendix = null ) where TModel : GovUkViewModel { var property = ExpressionHelpers.GetPropertyFromExpression(propertyLambdaExpression); var propertyName = property.Name; var model = htmlHelper.ViewData.Model; var id = $"GovUk_{propertyName}"; var currentValue = ExtensionHelpers.GetCurrentValue(model, property, propertyLambdaExpression); if (labelOptions != null) { labelOptions.For = id; } var textInputViewModel = new TextInputViewModel { Name = $"GovUk_Text_{propertyName}", Id = id, Value = currentValue, Label = labelOptions, Hint = hintOptions, FormGroup = formGroupOptions, Classes = classes, TextInputAppendix = textInputAppendix }; if (model.HasErrorFor(property)) { textInputViewModel.ErrorMessage = new ErrorMessageViewModel { Text = model.GetErrorFor(property) } } ; return(htmlHelper.Partial("~/Partials/TextInput.cshtml", textInputViewModel)); } }
public static IHtmlContent GovUkTextInput( this IHtmlHelper htmlHelper, TextInputViewModel textInputViewModel) { return(htmlHelper.Partial("/GovUkDesignSystemComponents/TextInput.cshtml", textInputViewModel)); }
public static IHtmlContent GovUkTextInput( this IHtmlHelper htmlHelper, TextInputViewModel textInputViewModel) { return(htmlHelper.Partial("~/Partials/TextInput.cshtml", textInputViewModel)); }