Add ability to specify culture and format

This lets us specify the associations between the HTML5 field types and
these settings.
This commit is contained in:
Ryan Nowak 2019-07-19 11:24:36 -07:00 committed by Ryan Nowak
parent 3aeee00899
commit af7ac7ff29
3 changed files with 33 additions and 11 deletions

View File

@ -18,10 +18,10 @@ namespace Microsoft.AspNetCore.Components
}
[Microsoft.AspNetCore.Components.BindElementAttribute("select", null, "value", "onchange")]
[Microsoft.AspNetCore.Components.BindElementAttribute("textarea", null, "value", "onchange")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("checkbox", null, "checked", "onchange")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("text", null, "value", "onchange")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute(null, "value", "value", "onchange")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute(null, null, "value", "onchange")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("checkbox", null, "checked", "onchange", false, null)]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("text", null, "value", "onchange", false, null)]
[Microsoft.AspNetCore.Components.BindInputElementAttribute(null, "value", "value", "onchange", false, null)]
[Microsoft.AspNetCore.Components.BindInputElementAttribute(null, null, "value", "onchange", false, null)]
public static partial class BindAttributes
{
}
@ -84,8 +84,10 @@ namespace Microsoft.AspNetCore.Components
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
public sealed partial class BindInputElementAttribute : System.Attribute
{
public BindInputElementAttribute(string type, string suffix, string valueAttribute, string changeAttribute) { }
public BindInputElementAttribute(string type, string suffix, string valueAttribute, string changeAttribute, bool isInvariantCulture, string format) { }
public string ChangeAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public string Format { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public bool IsInvariantCulture { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public string Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public string Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public string ValueAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }

View File

@ -13,14 +13,14 @@ namespace Microsoft.AspNetCore.Components
// Handles cases like <input @bind="..." /> - this is a fallback and will be ignored
// when a specific type attribute is applied.
[BindInputElement(null, null, "value", "onchange")]
[BindInputElement(null, null, "value", "onchange", isInvariantCulture: false, format: null)]
// Handles cases like <input @bind-value="..." /> - this is a fallback and will be ignored
// when a specific type attribute is applied.
[BindInputElement(null, "value", "value", "onchange")]
[BindInputElement(null, "value", "value", "onchange", isInvariantCulture: false, format: null)]
[BindInputElement("checkbox", null, "checked", "onchange")]
[BindInputElement("text", null, "value", "onchange")]
[BindInputElement("checkbox", null, "checked", "onchange", isInvariantCulture: false, format: null)]
[BindInputElement("text", null, "value", "onchange", isInvariantCulture: false, format: null)]
[BindElement("select", null, "value", "onchange")]
[BindElement("textarea", null, "value", "onchange")]

View File

@ -1,7 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Globalization;
namespace Microsoft.AspNetCore.Components
{
@ -18,7 +19,13 @@ namespace Microsoft.AspNetCore.Components
/// <param name="suffix">The suffix value.</param>
/// <param name="valueAttribute">The name of the value attribute to be bound.</param>
/// <param name="changeAttribute">The name of an attribute that will register an associated change event.</param>
public BindInputElementAttribute(string type, string suffix, string valueAttribute, string changeAttribute)
/// <param name="isInvariantCulture">
/// Determines whether binding will use <see cref="CultureInfo.InvariantCulture" /> or <see cref="CultureInfo.CurrentCulture"/>.
/// </param>
/// <param name="format">
/// An optional format to use when converting values.
/// </param>
public BindInputElementAttribute(string type, string suffix, string valueAttribute, string changeAttribute, bool isInvariantCulture, string format)
{
if (valueAttribute == null)
{
@ -34,6 +41,8 @@ namespace Microsoft.AspNetCore.Components
Suffix = suffix;
ValueAttribute = valueAttribute;
ChangeAttribute = changeAttribute;
IsInvariantCulture = isInvariantCulture;
Format = format;
}
/// <summary>
@ -55,5 +64,16 @@ namespace Microsoft.AspNetCore.Components
/// Gets the name of an attribute that will register an associated change event.
/// </summary>
public string ChangeAttribute { get; }
/// <summary>
/// Gets a value that determines whether binding will use <see cref="CultureInfo.InvariantCulture" /> or
/// <see cref="CultureInfo.CurrentCulture"/>.
/// </summary>
public bool IsInvariantCulture { get; }
/// <summary>
/// Gets an optional format to use when converting values.
/// </summary>
public string Format { get; }
}
}