Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add start day of week option #2007

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Demos/Blazorise.Demo/Pages/Tests/FormsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<Field Horizontal="true">
<FieldLabel ColumnSize="ColumnSize.IsFull.OnTablet.Is2.OnDesktop">Date</FieldLabel>
<FieldBody ColumnSize="ColumnSize.IsFull.OnTablet.Is10.OnDesktop">
<DateEdit TValue="DateTime?" />
<DateEdit TValue="DateTime?" StartDayOfWeek="0" />
</FieldBody>
</Field>
<Field Horizontal="true">
Expand Down
6 changes: 3 additions & 3 deletions Source/Blazorise.Material/MaterialJSRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public override ValueTask<bool> InitializeTooltip( ElementReference elementRef,
return runtime.InvokeAsync<bool>( $"blazoriseMaterial.tooltip.initialize", elementRef, elementId );
}

public override ValueTask<bool> ActivateDatePicker( string elementId, string formatSubmit )
{
return runtime.InvokeAsync<bool>( $"blazoriseMaterial.activateDatePicker", elementId, formatSubmit );
public override ValueTask<bool> ActivateDatePicker( string elementId, string formatSubmit, int startDayOfWeek )
{
return runtime.InvokeAsync<bool>( $"blazoriseMaterial.activateDatePicker", elementId, formatSubmit, startDayOfWeek );
}

public override ValueTask<bool> OpenModal( ElementReference elementRef, bool scrollToTop )
Expand Down
6 changes: 4 additions & 2 deletions Source/Blazorise.Material/wwwroot/blazorise.material.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ window.blazoriseMaterial = {
return true;
}
},
activateDatePicker: (elementId, formatSubmit) => {
activateDatePicker: (elementId, formatSubmit, startDayOfWeek) => {
const element = $(`#${elementId}`);
startDayOfWeek = startDayOfWeek || 0;
startDayOfWeek = startDayOfWeek < 0 ? 0 : startDayOfWeek > 6 ? 6 : startDayOfWeek;

element.pickdate({
ok: '',
Expand All @@ -23,7 +25,7 @@ window.blazoriseMaterial = {
closeOnSelect: true,
container: 'body',
containerHidden: 'body',
firstDay: 1, // monday
firstDay: startDayOfWeek,
format: 'dd.mm.yyyy',
selectMonths: true,
selectYears: true,
Expand Down
8 changes: 7 additions & 1 deletion Source/Blazorise/Components/DateEdit/DateEdit.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected async Task OnClickHandler( MouseEventArgs e )
if ( Disabled || ReadOnly )
return;

await JSRunner.ActivateDatePicker( ElementId, DateFormat );
await JSRunner.ActivateDatePicker( ElementId, DateFormat, StartDayOfWeek );
}

/// <inheritdoc/>
Expand Down Expand Up @@ -153,6 +153,12 @@ protected override Task OnBlurHandler( FocusEventArgs eventArgs )
/// </summary>
[Parameter] public TValue Date { get; set; }

/// <summary>
/// Gets or sets the startDayOfWeek, 0 = Sunday, ..., 6 = Saturday
/// Only applies to Blazorise material and defaults at Monday
/// </summary>
[Parameter] public int StartDayOfWeek { get; set; } = 1;

/// <summary>
/// Occurs when the date has changed.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/Interfaces/IJSRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface IJSRunner

ValueTask<DomElement> GetElementInfo( ElementReference elementRef, string elementId );

ValueTask<bool> ActivateDatePicker( string elementId, string formatSubmit );
ValueTask<bool> ActivateDatePicker( string elementId, string formatSubmit, int startDayOfWeek );

ValueTask<bool> ActivateTimePicker( string elementId, string formatSubmit );

Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/JSRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public ValueTask<DomElement> GetElementInfo( ElementReference elementRef, string
/// </summary>
/// <param name="elementId">Input element id.</param>
/// <param name="formatSubmit">Date format to submit.</param>
public virtual ValueTask<bool> ActivateDatePicker( string elementId, string formatSubmit )
public virtual ValueTask<bool> ActivateDatePicker( string elementId, string formatSubmit, int startDayOfWeek )
{
// must be implemented by a framework provider!
return new ValueTask<bool>( true );
Expand Down
2 changes: 1 addition & 1 deletion Tests/Blazorise.Tests/Mocks/MockDateEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public MockDateEdit( Validation validation = null, Expression<Func<T>> dateExpre
var mockRunner = new Mock<IJSRunner>();

mockRunner
.Setup( r => r.ActivateDatePicker( It.IsAny<string>(), It.IsAny<string>() ) )
.Setup( r => r.ActivateDatePicker( It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>() ) )
.Callback( ( string id, string f ) => this.OnActivateDatePicker( id, f ) );

base.JSRunner = mockRunner.Object;
Expand Down