gives the billing line description a maximum length
This commit is contained in:
parent
310b69a7bd
commit
2b02d8c01a
2 changed files with 38 additions and 3 deletions
|
|
@ -7,6 +7,35 @@ using Xamarin.Forms;
|
||||||
|
|
||||||
namespace BookAStar.Behaviors
|
namespace BookAStar.Behaviors
|
||||||
{
|
{
|
||||||
|
public class EditorMaxLengthValidator : Behavior<Editor>
|
||||||
|
{
|
||||||
|
public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create("MaxLength", typeof(int), typeof(MaxLengthValidator), 0);
|
||||||
|
|
||||||
|
public int MaxLength
|
||||||
|
{
|
||||||
|
get { return (int)GetValue(MaxLengthProperty); }
|
||||||
|
set { SetValue(MaxLengthProperty, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAttachedTo(Editor bindable)
|
||||||
|
{
|
||||||
|
bindable.TextChanged += bindable_TextChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsValid { get; set; }
|
||||||
|
|
||||||
|
private void bindable_TextChanged(object sender, TextChangedEventArgs e)
|
||||||
|
{
|
||||||
|
IsValid = e.NewTextValue.Length <= 0 || e.NewTextValue.Length <= MaxLength;
|
||||||
|
if (!IsValid && e.NewTextValue.Length > MaxLength)
|
||||||
|
((Editor)sender).Text = e.NewTextValue.Substring(0, MaxLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDetachingFrom(Editor bindable)
|
||||||
|
{
|
||||||
|
bindable.TextChanged -= bindable_TextChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
public class MaxLengthValidator : Behavior<Entry>
|
public class MaxLengthValidator : Behavior<Entry>
|
||||||
{
|
{
|
||||||
public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create("MaxLength", typeof(int), typeof(MaxLengthValidator), 0);
|
public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create("MaxLength", typeof(int), typeof(MaxLengthValidator), 0);
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,14 @@
|
||||||
|
|
||||||
<Label Text="Description de la ligne de facture"
|
<Label Text="Description de la ligne de facture"
|
||||||
Style="{StaticResource InputLabelStyle}"></Label>
|
Style="{StaticResource InputLabelStyle}"></Label>
|
||||||
<Editor VerticalOptions="FillAndExpand" Text="{Binding Description, Mode=TwoWay}" ></Editor>
|
<Editor VerticalOptions="FillAndExpand" Text="{Binding Description, Mode=TwoWay}">
|
||||||
|
<Editor.Behaviors>
|
||||||
|
<behaviors:EditorMaxLengthValidator x:Name="descriptionValidator" MaxLength="512" />
|
||||||
|
</Editor.Behaviors>
|
||||||
|
</Editor>
|
||||||
|
<Image Style="{Binding Source={x:Reference descriptionValidator},
|
||||||
|
Path=IsValid,
|
||||||
|
Converter={StaticResource boolToStyleImage}}" />
|
||||||
<Label Text="Durée de la prestation"
|
<Label Text="Durée de la prestation"
|
||||||
Style="{StaticResource InputLabelStyle}"></Label>
|
Style="{StaticResource InputLabelStyle}"></Label>
|
||||||
<StackLayout Orientation="Horizontal">
|
<StackLayout Orientation="Horizontal">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue