-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
NumericField-Spinner.Edit.cshtml
64 lines (60 loc) · 3.17 KB
/
NumericField-Spinner.Edit.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@model OrchardCore.ContentFields.ViewModels.EditNumericFieldViewModel
@using System.Globalization
@using OrchardCore.ContentManagement.Metadata.Models
@using OrchardCore.ContentFields.Settings
@using OrchardCore.Mvc.Utilities
@{
var settings = Model.PartFieldDefinition.GetSettings<NumericFieldSettings>();
string name = Model.PartFieldDefinition.DisplayName();
int scale = settings.Scale;
string step = Math.Pow(10, 0 - settings.Scale).ToString(CultureInfo.InvariantCulture);
decimal min = settings.Minimum.HasValue ? settings.Minimum.Value : 0;
decimal max = settings.Maximum.HasValue ? settings.Maximum.Value : 10000;
string id = Html.IdFor(m => m.Value);
string javascriptDecimalSeparator = CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator;
string serverDecimalSeparator = CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
}
<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Value)_FieldWrapper">
<label asp-for="Value" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@name</label>
<div class="@Orchard.GetEndClasses()">
<div class="@Orchard.GetLimitedWidthWrapperClasses()">
<div class="@Orchard.GetLimitedWidthClasses()">
<div class="input-group">
@if (settings.Minimum.HasValue)
{
<span class="input-group-text">@min</span>
}
<input asp-for="Value" typeof="text" class="form-control content-preview-select" placeholder="@settings.Placeholder" />
<button class="btn btn-outline-secondary" type="button" onclick="numericFieldSpinner('@(id)', @(scale), -@(step), @(min), @(max))"><i class="fa-solid fa-minus" aria-hidden="true"></i></button>
<button class="btn btn-outline-secondary" type="button" onclick="numericFieldSpinner('@(id)', @(scale), +@(step), @(min), @(max))"><i class="fa-solid fa-plus" aria-hidden="true"></i></button>
@if (settings.Maximum.HasValue)
{
<span class="input-group-text">@max</span>
}
</div>
</div>
</div>
@if (!string.IsNullOrEmpty(settings.Hint))
{
<span class="hint">@settings.Hint</span>
}
</div>
</div>
<script asp-name="numericFieldSpinner" at="Foot">
function numericFieldSpinner(id, scale, step, min, max) {
let value = $('#' + id).val();
@if (javascriptDecimalSeparator != serverDecimalSeparator)
{
<text>value = value.replace('@(serverDecimalSeparator)', '@(javascriptDecimalSeparator)'); </text>
}
value = (Number(value) || 0) + step;
value = Math.min(value, max); // Never go above max
value = Math.max(value, min); // or below min
value = Number(value.toFixed(scale)).toString(); // Drop insignificant trailing zeros
@if (javascriptDecimalSeparator != serverDecimalSeparator)
{
<text>value = value.replace('@(javascriptDecimalSeparator)', '@(serverDecimalSeparator)'); </text>
}
$('#' + id).val(value);
}
</script>