Skip to content

Commit

Permalink
property-value-converter functional
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendy committed Jun 18, 2018
1 parent 4c5ac4e commit 69384c4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Our.Umbraco.NullableTypes.PropertyEditors;
using Newtonsoft.Json.Linq;
using Our.Umbraco.NullableTypes.PropertyEditors;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;

Expand Down Expand Up @@ -31,6 +32,43 @@ public override object ConvertSourceToObject(PublishedPropertyType publishedProp

if (source != null)
{
if (source is int)
{
nullableInteger = (int)source;
}
else if (source is string)
{
var sourceString = source.ToString();

if (int.TryParse(sourceString, out int sourceStringParsed))
{
nullableInteger = sourceStringParsed;
}
else
{
try
{
var value = JObject.Parse(sourceString);

if (value.Type == JTokenType.Object)
{
var checkbox = (bool)value["checkbox"];
var number = (string)value["number"];

if (checkbox)
{
if (int.TryParse(number, out int numberParsed))
{
nullableInteger = numberParsed;
}
}
}
}
catch
{
}
}
}
}

return nullableInteger;
Expand Down
6 changes: 3 additions & 3 deletions src/Our.Umbraco.NullableTypes/Resources/NullableInteger.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
ng-change="checkboxChange()"/>

<input type="number"
pattern="[0-9]*"
min="{{model.config.minimumValue}}"
max="{{model.config.maximumValue}}"
step="{{model.config.stepSize}}"
class=""
pattern="/^-?[0-9][^\.]*$/"
class="umb-number"
ng-model="model.number"
ng-disabled="!(model.value.checkbox)"
fix-number />
ng-required="model.value.checkbox"/>

</div>

0 comments on commit 69384c4

Please sign in to comment.