Skip to content

Commit

Permalink
fix: can't submit non-integer value in decimal field
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzliera committed Sep 17, 2021
1 parent 484161d commit b3b8236
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="input-field s12">
<div class="input-field">
<input id="{PropertyId}" name="{PropertyId}" value="{Value}" type="number" class="validate" />
<input id="{PropertyId}" name="{PropertyId}" value="{Value}" type="number" step="{Step}" class="validate" />
<label for="{PropertyId}">{PropertyName}</label>
</div>
</div>
37 changes: 20 additions & 17 deletions ConfigurationUi/Ui/UiBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ private void InitializeTemplates()
_arrayEditorComponent = ReadComponentTemplate("ArrayEditor");
_arrayElementTemplate = ReadComponentTemplate("ArrayEditor", "ArrayElement");
}


public string BuildHtml(IConfiguration configuration, JsonSchema schema)
{
var htmlBuilder = new StringBuilder(_rootUiHtml);
Expand All @@ -89,27 +89,24 @@ private StringBuilder GenerateHtmlRecursive(IConfigurationSection configuration,
return BuildDropDownEditorHtml(configuration, schema);
}

if (schema.Type.HasFlag(JsonObjectType.String))
return BuildTextEditorHtml(configuration);
if (schema.Type.HasFlag(JsonObjectType.Boolean))
return BuildBooleanEditor(configuration);
if (schema.Type.HasFlag(JsonObjectType.Number))
return BuildNumberEditorHtml(configuration);
if (schema.Type.HasFlag(JsonObjectType.Integer)) return BuildNumberEditorHtml(configuration);
if (schema.Type.HasFlag(JsonObjectType.String)) return BuildTextEditorHtml(configuration);
if (schema.Type.HasFlag(JsonObjectType.Boolean)) return BuildBooleanEditor(configuration);
if (schema.Type.HasFlag(JsonObjectType.Number)) return BuildDecimalEditorHtml(configuration);
if (schema.Type.HasFlag(JsonObjectType.Integer)) return BuildIntegerEditorHtml(configuration);


if (schema.IsObject) return BuildObjectEditorHtml(configuration, schema);

if (schema.IsArray) return BuildArrayEditorHtml(configuration, schema);

if (schema.Type == JsonObjectType.None)
{
if (schema.OneOf.Count == 2 && schema.OneOf.First().Type == JsonObjectType.Null)
return GenerateHtmlRecursive(configuration, schema.OneOf.Last());

if (schema.HasReference) return GenerateHtmlRecursive(configuration, schema.Reference);
}

// TODO support Dictionaries
throw new NotSupportedException();
}
Expand All @@ -135,7 +132,7 @@ private StringBuilder BuildArrayEditorHtml(IConfigurationSection configuration,
var elemSchema = schema.Item; // TODO support mixed schema arrays

var elemsBuilder = new StringBuilder();

foreach (var arrayElemSection in configuration.GetChildren())
{
var singleElementBuilder = new StringBuilder(_arrayElementTemplate);
Expand Down Expand Up @@ -164,7 +161,6 @@ private StringBuilder BuildBooleanEditor(IConfigurationSection configuration)

private StringBuilder BuildDropDownEditorHtml(IConfigurationSection configuration, JsonSchema schema)
{

// TODO support flags enum

var dropDownEditorBuilder = new StringBuilder(_dropDownEditorComponent)
Expand All @@ -189,11 +185,18 @@ private StringBuilder BuildDropDownEditorHtml(IConfigurationSection configuratio
return dropDownEditorBuilder;
}

private StringBuilder BuildNumberEditorHtml(IConfigurationSection configuration)
private StringBuilder BuildIntegerEditorHtml(IConfigurationSection configuration)
{
return FormatComponent(configuration, _numericEditorHtmlComponent);
return FormatComponent(configuration, _numericEditorHtmlComponent)
.Replace("{Step}", "1");
}


private StringBuilder BuildDecimalEditorHtml(IConfigurationSection configuration)
{
return FormatComponent(configuration, _numericEditorHtmlComponent)
.Replace("{Step}", "any");
}


private static StringBuilder FormatComponent(IConfigurationSection configuration, string template)
{
Expand Down Expand Up @@ -232,7 +235,7 @@ private string ReadRootTemplate()
var templatesFolder = Path.Combine(_assemblyBasePath, TemplatesFolderPath);
var rootTemplatePath = Path.Combine(templatesFolder, RootTemplateName);
var rootHtmlBuilder = new StringBuilder(File.ReadAllText(rootTemplatePath));

var scriptsBuilder = new StringBuilder();
foreach (var filePath in Directory.GetFiles(templatesFolder, "*.Scripts.html", SearchOption.AllDirectories))
{
Expand Down

0 comments on commit b3b8236

Please sign in to comment.