static string?GetUserErrorMessageOrDefault(ModelError error, ModelState?modelState)
        {
            if (!String.IsNullOrEmpty(error.ErrorMessage))
            {
                return(error.ErrorMessage);
            }

            if (modelState is null)
            {
                return(null);
            }

            string?attemptedValue = modelState.Value?.AttemptedValue;

            string messageFormat = XcstWebConfiguration.Instance.EditorTemplates.DefaultValidationMessage?.Invoke()
                                   ?? "The value '{0}' is invalid.";

            return(String.Format(CultureInfo.CurrentCulture, messageFormat, attemptedValue));
        }
Beispiel #2
0
 /// <summary>
 /// Get an existing Model resource's state with the given name, ID, and optional extra
 /// properties used to qualify the lookup.
 /// </summary>
 ///
 /// <param name="name">The unique name of the resulting resource.</param>
 /// <param name="id">The unique provider ID of the resource to lookup.</param>
 /// <param name="state">Any extra arguments used during the lookup.</param>
 /// <param name="options">A bag of options that control this resource's behavior</param>
 public static Model Get(string name, Input <string> id, ModelState?state = null, CustomResourceOptions?options = null)
 {
     return(new Model(name, id, state, options));
 }
Beispiel #3
0
 private Model(string name, Input <string> id, ModelState?state = null, CustomResourceOptions?options = null)
     : base("aws:apigateway/model:Model", name, state, MakeResourceOptions(options, id))
 {
 }
        internal static void ValidationMessageHelper(
            HtmlHelper htmlHelper, XcstWriter output, ModelMetadata modelMetadata, string expression, string?validationMessage,
            HtmlAttribs?htmlAttributes, string?tag)
        {
            ViewDataDictionary viewData = htmlHelper.ViewData;

            string      modelName   = viewData.TemplateInfo.GetFullHtmlFieldName(expression);
            FormContext?formContext = htmlHelper.ViewContext.GetFormContextForClientValidation();

            if (!viewData.ModelState.ContainsKey(modelName) &&
                formContext is null)
            {
                return;
            }

            ModelState?          modelState  = viewData.ModelState[modelName];
            ModelErrorCollection?modelErrors = modelState?.Errors;

            ModelError?modelError = (modelErrors is null || modelErrors.Count == 0) ? null
            : (modelErrors.FirstOrDefault(m => !String.IsNullOrEmpty(m.ErrorMessage)) ?? modelErrors[0]);

            if (modelError is null &&
                formContext is null)
            {
                return;
            }

            if (String.IsNullOrEmpty(tag))
            {
                tag = htmlHelper.ViewContext.ValidationMessageElement;
            }

            string validationClass = (modelError != null) ?
                                     HtmlHelper.ValidationMessageCssClassName
            : HtmlHelper.ValidationMessageValidCssClassName;

            output.WriteStartElement(tag !);
            HtmlAttributeHelper.WriteClass(validationClass, htmlAttributes, output);

            if (formContext != null)
            {
                bool replaceValidationMessageContents = String.IsNullOrEmpty(validationMessage);

                if (htmlHelper.ViewContext.UnobtrusiveJavaScriptEnabled)
                {
                    output.WriteAttributeString("data-valmsg-for", modelName);
                    output.WriteAttributeString("data-valmsg-replace", replaceValidationMessageContents.ToString().ToLowerInvariant());
                }
            }

            // class was already written

            HtmlAttributeHelper.WriteAttributes(htmlAttributes, output, excludeFn: n => n == "class");

            if (!String.IsNullOrEmpty(validationMessage))
            {
                output.WriteString(validationMessage);
            }
            else if (modelError != null)
            {
                output.WriteString(GetUserErrorMessageOrDefault(modelError, modelState));
            }

            output.WriteEndElement();
        }