PDA

View Full Version : [CLOSED] What's the Razor syntax for InputMask?



AmitM
Sep 25, 2013, 3:41 AM
Tried, but could not convert this:



<ext:TextField runat="server" FieldLabel="Custom placeholders" Note="Input a date">
<Plugins>
<ext:InputMask runat="server" Mask="dt/mn/yzzz">
<MaskSymbols>
<ext:MaskSymbol Name="d" Regex="[0123]" Placeholder="d" />
<ext:MaskSymbol Name="t" Regex="[0-9]" Placeholder="d" />
<ext:MaskSymbol Name="m" Regex="[01]" Placeholder="m" />
<ext:MaskSymbol Name="n" Regex="[0-9]" Placeholder="m" />
<ext:MaskSymbol Name="y" Regex="[12]" Placeholder="y" />
<ext:MaskSymbol Name="z" Regex="[0-9]" Placeholder="y" />
</MaskSymbols>
</ext:InputMask>
</Plugins>
</ext:TextField>



to Razor format.

Help...

Daniil
Sep 25, 2013, 5:36 AM
Hi @AmitM,

Here you are.

Example

@(Html.X().TextField()
.Plugins(X.InputMask()
.Mask("dt/mn/yzzz")
.MaskSymbols(symbols =>
{
symbols.Add(new MaskSymbol() { Name = "d", Regex = "[0123]", Placeholder = 'd' });
symbols.Add(new MaskSymbol() { Name = "t", Regex = "[0-9]", Placeholder = 'd' });
/* the rest symbols */
}
)
)
)

AmitM
Sep 26, 2013, 2:05 AM
I need to use this as an input mask for time. In the DB, I have values as a string with a format necessary for a seperate export function.

An example time is "05:00 PM". They are all stored as string per requirements.

I am using this for the input mask:


.Plugins(Html.X().InputMask()
.Mask("hH:mM aM")
.ClearWhenInvalid(false)
.MaskSymbols(symbols =>
{
symbols.Add(new MaskSymbol() { Name = "h", Regex = "[01]" });
symbols.Add(new MaskSymbol() { Name = "H", Regex = "[0-9]" });
symbols.Add(new MaskSymbol() { Name = "m", Regex = "[0-5]" });
symbols.Add(new MaskSymbol() { Name = "M", Regex = "[0-9]" });
symbols.Add(new MaskSymbol() { Name = "a", Regex = "[aApP]" });
}
)
)


It works fine when the field is blank. However, when the field is already populated from the DB, the field goes blank as soon as I click in it to edit.

Am I missing some property?

Thanks,
Amit

AmitM
Sep 26, 2013, 2:31 AM
I was missing



.AllowInvalid(true)