2
0
lviguier 1 жил өмнө
parent
commit
5e4b5292c9
1 өөрчлөгдсөн 24 нэмэгдсэн , 13 устгасан
  1. 24 13
      hide/comp/cdb/Cell.hx

+ 24 - 13
hide/comp/cdb/Cell.hx

@@ -1004,7 +1004,7 @@ class Cell {
 				elementHtml.classList.add("edit");
 				var cellEl = new Element(elementHtml);
 				var paddingCell = 4;
-				editCustomType(typeName, currentValue, cellEl, js.Browser.document.body.clientWidth - (cellEl.offset().left + paddingCell + (cellEl.width() + paddingCell) / 2.0), cellEl.offset().top);
+				editCustomType(typeName, currentValue, column, cellEl, js.Browser.document.body.clientWidth - (cellEl.offset().left + paddingCell + (cellEl.width() + paddingCell) / 2.0), cellEl.offset().top);
 			}
 		case TColor:
 			var elem = new Element(elementHtml);
@@ -1279,8 +1279,9 @@ class Cell {
 		focus();
 	}
 
-	public function editCustomType(typeName : String, currentValue : Dynamic, parentEl : Element, rightAnchor: Float, topAnchor : Float, depth : Int = 0) {
+	public function editCustomType(typeName : String, currentValue : 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('<div class="cdb-type-string"></div>').appendTo(parentEl);
@@ -1308,7 +1309,7 @@ class Cell {
 						el.attr("checked", "true");
 					return el;
 				case TInt, TFloat:
-					return new Element('<input type="number" ${value != null ? 'value="${value}"': ''}></input>');
+					return new Element('<input type="number" ${'value="${value != null ? value : 0}"'}></input>');
 				case TRef(name):
 					{
 						var sdat = editor.base.getSheet(name);
@@ -1375,12 +1376,18 @@ class Cell {
 				case TCustom(name):
 					{
 						var valueHtml = this.valueHtml(column, value, line.table.getRealSheet(), currentValue, []);
-						var html = new Element('<div class="sub-cdb-type"><p>${valueHtml.str}</p></div>').css("min-width","80px").css("background-color","#222222");
+
+						// 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 ) valueHtml.containsHtml ? valueHtml.str : '<span class="error">#NULL</span>';
+
+						var html = new Element('<div class="sub-cdb-type"><p>${valueStr}</p></div>').css("min-width","80px").css("background-color","#222222");
 						html.on("click", function(e) {
 							// When opening one custom type, close others of the same level
 							content.find(".cdb-type-string").trigger("click");
 
-							editCustomType(name, value, html, content.width() - html.position().left - html.width(), 25, depth + 1);
+							editCustomType(name, value, column, html, content.width() - html.position().left - html.width(), 25, depth + 1);
 						});
 
 						return html;
@@ -1391,8 +1398,8 @@ class Cell {
 		}
 
 		var d = content.find("#dropdown-custom-type");
-		if (currentValue != null)
-			d.find("option").eq(Std.int(currentValue[0] + 1)).attr("selected", "true");
+		if (depth == 0 ? currentValue != null : parsedValue != null)
+			d.find("option").eq(Std.int(depth == 0 ? currentValue[0] + 1 : parsedValue[0] + 1)).attr("selected", "true");
 
 		var paramsContent = content.find("#parameters");
 
@@ -1404,9 +1411,8 @@ class Cell {
 			if (selected != null && selected.args.length > 0) {
 				for (idx in 0...selected.args.length) {
 					new Element('<p>&nbsp${selected.args[idx].name}&nbsp:</p>').appendTo(paramsContent);
-
-					var paramVal = cast currentValue;
-					getHtml(currentValue != null ? currentValue[idx + 1] : null, selected.args[idx]).addClass("value").appendTo(paramsContent);
+					var paramVal = depth == 0 ? cast currentValue : parsedValue;
+					getHtml(paramVal != null ? paramVal[idx + 1] : null, selected.args[idx]).addClass("value").appendTo(paramsContent);
 
 					if (idx != selected.args.length - 1)
 						new Element('<p>,&nbsp</p>').appendTo(paramsContent);
@@ -1441,11 +1447,12 @@ class Cell {
 							if (sel.val() != 0)
 								stringValue += sel.text();
 							else
-								stringValue += "null";
+								stringValue += "";
 						}
 						else if (paramValue.is("div")) {
 							// Case where the param value is another cdbType
-							stringValue += paramValue.children().first().text();
+							var v = paramValue.children().first().text();
+							stringValue += v;
 						}
 						else
 							stringValue += paramsValues.eq(idx).val();
@@ -1458,11 +1465,15 @@ class Cell {
 				}
 			}
 			else {
-				stringValue = "null";
+				stringValue = "";
 			}
 
 			parentEl.empty();
 
+			// Check if the value is correct
+			var newValue = try editor.base.parseValue(TCustom(customType.name), stringValue, false) catch( e : Dynamic ) null;
+			stringValue = valueHtml(col, newValue, line.table.getRealSheet(), currentValue, []).str;
+
 			if (depth == 0) {
 				this.setRawValue(stringValue);
 				this.closeEdit();