Exemplo n.º 1
0
        /// <summary>
        ///     Render TextArea view component.
        /// </summary>
        /// <param name="aspFor"></param>
        /// <param name="label"></param>
        /// <param name="populateWithCurrentValue"></param>
        /// <param name="rows"></param>
        /// <param name="spellCheck"></param>
        /// <param name="hintText">Leave blank for no hint.</param>
        /// <param name="cssClass"></param>
        /// <param name="characterCount"></param>
        /// <returns></returns>
        public IViewComponentResult Invoke(
            string aspFor,
            string label,
            bool populateWithCurrentValue,
            int rows,
            bool spellCheck,
            string hintText,
            string cssClass,
            int?characterCount)
        {
            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 TextAreaViewModel(
                aspFor,
                aspFor,
                label,
                valueToSet,
                rows,
                spellCheck,
                errorMessages,
                string.IsNullOrEmpty(cssClass) ? null : cssClass,
                string.IsNullOrEmpty(hintText) ? null : hintText,
                characterCount);

            return(View(textBoxViewModel));
        }
        public IActionResult TextArea(TextAreaViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                return(this.View("TextAreaResult", model));
            }

            return(this.View(model));
        }
Exemplo n.º 3
0
 private void SetTextAreaMode(TextViewMode textViewMode)
 {
     if (this.mainPivot.Items.Count >= 3)
     {
         PivotItem         textAreaPivot     = (PivotItem)this.mainPivot.Items[2];
         TextArea          textArea          = (TextArea)textAreaPivot.Content;
         TextAreaViewModel textAreaViewModel = (TextAreaViewModel)textArea.DataContext;
         textAreaViewModel.TextViewMode = textViewMode;
     }
 }
        internal static IHtmlContent GenerateHtml <TModel>(
            IHtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, string> > propertyLambdaExpression,
            int?rows = null,
            LabelViewModel labelOptions         = null,
            HintViewModel hintOptions           = null,
            FormGroupViewModel formGroupOptions = 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 textAreaViewModel = new TextAreaViewModel
            {
                Name      = $"GovUk_Text_{propertyName}",
                Id        = id,
                Value     = currentValue,
                Rows      = rows,
                Label     = labelOptions,
                Hint      = hintOptions,
                FormGroup = formGroupOptions
            };

            if (model.HasErrorFor(property))
            {
                textAreaViewModel.ErrorMessage = new ErrorMessageViewModel {
                    Text = model.GetErrorFor(property)
                };
            }

            return(htmlHelper.Partial("/GovUkDesignSystemComponents/Textarea.cshtml", textAreaViewModel));
        }
 public static IHtmlContent GovUkTextArea(
     this IHtmlHelper htmlHelper,
     TextAreaViewModel textAreaViewModel)
 {
     return(htmlHelper.Partial("/GovUkDesignSystemComponents/TextArea.cshtml", textAreaViewModel));
 }
Exemplo n.º 6
0
 public static IHtmlContent GovUkTextArea(
     this IHtmlHelper htmlHelper,
     TextAreaViewModel textAreaViewModel)
 {
     return(htmlHelper.Partial("~/Partials/TextArea.cshtml", textAreaViewModel));
 }