diff --git a/hide/comp/cdb/Cell.hx b/hide/comp/cdb/Cell.hx index 0e7a4acf7..3ee114c29 100644 --- a/hide/comp/cdb/Cell.hx +++ b/hide/comp/cdb/Cell.hx @@ -1279,9 +1279,8 @@ class Cell { focus(); } - public function editCustomType(typeName : String, currentValue : Dynamic, col : cdb.Data.Column, parentEl : Element, rightAnchor: Float, topAnchor : Float, depth : Int = 0) { + public function editCustomType(typeName : String, ctValue : Dynamic, col : cdb.Data.Column, parentEl : Element, rightAnchor: Float, topAnchor : Float, depth : Int = 0) { var customType = editor.base.getCustomType(typeName); - var parsedValue = try editor.base.parseValue(col.type, parentEl.text(), false) catch( e : Dynamic ) null; parentEl.empty(); var rootEl = new Element('
').appendTo(parentEl); @@ -1462,21 +1461,13 @@ class Cell { } case TCustom(name): { - var valueHtml = this.valueHtml(column, value, line.table.getRealSheet(), currentValue, []); - - // Check if the value is a valid one - var valueStr = try { - this.valueHtml(column, editor.base.parseValue(column.type, valueHtml.str, false), line.table.getRealSheet(), currentValue, []).str; - } catch( e : Dynamic ) { - if (valueHtml.containsHtml) - valueHtml.str; - else if (column.opt) - ''; - else - '#NULL'; - } + var valueHtml = this.valueHtml(column, value, line.table.getRealSheet(), ctValue, []); + var display = '#NULL'; - var html = new Element('${valueStr}
${display}
 ${selected.args[idx].name} :
').appendTo(paramsContent); - var paramVal = depth == 0 ? cast currentValue : parsedValue; - getHtml(paramVal != null ? paramVal[idx + 1] : null, selected.args[idx]).addClass("value").appendTo(paramsContent); + getHtml(ctValue != null ? ctValue[idx + 1] : null, selected.args[idx]).addClass("value").appendTo(paramsContent); if (idx != selected.args.length - 1) new Element(', 
').appendTo(paramsContent); @@ -1567,17 +1556,25 @@ class Cell { parentEl.empty(); // Check if the value is correct - var newValue = try editor.base.parseValue(TCustom(customType.name), stringValue, false) catch( e : Dynamic ) null; - var htmlValue = valueHtml(col, applyModifications ? newValue : currentValue, line.table.getRealSheet(), currentValue, []); - if (StringTools.contains(htmlValue.str, '${stringValue}').appendTo(parentEl); parentEl.focus(); } @@ -1586,6 +1583,28 @@ class Cell { buildParameters(); d.on("change", function(e) { + if (ctValue == null) ctValue = []; + for (idx in 0...ctValue.length) ctValue.pop(); + + var selected = d.val() == 0 ? null : customType.cases[d.val()]; + if (selected != null) { + ctValue.push(d.val()); + for (idx in 0...selected.args.length) { + switch (selected.args[idx].type) { + case TId, TString, TRef(_): + ctValue.push(''); + case TBool: + ctValue.push(false); + case TInt, TFloat: + ctValue.push(0); + case TCustom(_), TList, TEnum(_): + ctValue.push([]); + default: + ctValue.push(null); + } + } + } + var t = this.currentValue; buildParameters(); });