@alifd/field
Advanced tools
Comparing version 1.1.8 to 1.1.9
@@ -25,3 +25,3 @@ --- | ||
this.state = { | ||
tableSource: [1, 2, 3].map(i => { | ||
tableSource: [0, 1, 2, 3].map(i => { | ||
return { id: i }; | ||
@@ -58,3 +58,3 @@ }) | ||
input = (value, index) => <Input {...this.field.init(`name.${index}`, { initValue: index })} />; | ||
input = (value, index) => <Input {...this.field.init(`name.${index}.input`, { initValue: index })} />; | ||
delete = (value, index) => <Button warning onClick={this.removeItem.bind(this, index)}>delete</Button>; | ||
@@ -61,0 +61,0 @@ |
--- | ||
title: Functional Component with React Hooks | ||
title: Hooks | ||
order: 12 | ||
@@ -4,0 +4,0 @@ --- |
@@ -495,2 +495,3 @@ "use strict"; | ||
} else { | ||
// because of shallow merge | ||
// if no value then copy values from fieldsMeta to keep initialized component data | ||
@@ -1000,4 +1001,4 @@ _this6.values = (0, _utils.setIn)(_this6.values, name, _this6.fieldsMeta[name].value); | ||
if (keyMatch.indexOf('{index}') === -1) { | ||
(0, _utils.warning)('{index} not find in key'); | ||
if (keyMatch.match(/{index}$/) === -1) { | ||
(0, _utils.warning)('key should match /{index}$/'); | ||
return; | ||
@@ -1008,4 +1009,10 @@ } // regex to match field names in the same target array | ||
var reg = keyMatch.replace('{index}', '(\\d+)'); | ||
var keyReg = new RegExp("^".concat(reg, "$")); | ||
var list = []; | ||
var keyReg = new RegExp("^".concat(reg)); | ||
var listMap = {}; | ||
/** | ||
* keyMatch='key.{index}' | ||
* case 1: names=['key.0', 'key.1'], should delete 'key.1' | ||
* case 2: names=['key.0.name', 'key.0.email', 'key.1.name', 'key.1.email'], should delete 'key.1.name', 'key.1.email' | ||
*/ | ||
var names = this.getNames(); | ||
@@ -1020,22 +1027,40 @@ names.forEach(function (n) { | ||
if (index > startIndex) { | ||
list.push({ | ||
index: index, | ||
name: n | ||
}); | ||
var l = listMap[index]; | ||
var item = { | ||
from: n, | ||
to: "".concat(keyMatch.replace('{index}', index - 1)).concat(n.replace(ret[0], '')) | ||
}; | ||
if (!l) { | ||
listMap[index] = [item]; | ||
} else { | ||
l.push(item); | ||
} | ||
} | ||
} | ||
}); | ||
list = list.sort(function (a, b) { | ||
var idxList = Object.keys(listMap).map(function (i) { | ||
return { | ||
index: Number(i), | ||
list: listMap[i] | ||
}; | ||
}).sort(function (a, b) { | ||
return a.index < b.index; | ||
}); // should be continuous array | ||
if (list.length > 0 && list[0].index === startIndex + 1) { | ||
list.forEach(function (l) { | ||
var n = keyMatch.replace('{index}', l.index - 1); | ||
if (idxList.length > 0 && idxList[0].index === startIndex + 1) { | ||
idxList.forEach(function (l) { | ||
var list = l.list; | ||
list.forEach(function (i) { | ||
var v = _this13.getValue(i.from); // get index value | ||
var v = _this13.getValue(l.name); | ||
_this13.setValue(n, v, false); | ||
_this13.setValue(i.to, v, false); // set value to index - 1 | ||
}); | ||
}); | ||
this.remove(list[list.length - 1].name); | ||
var lastIdxList = idxList[idxList.length - 1]; | ||
lastIdxList.list.forEach(function (i) { | ||
_this13.remove(i.from); | ||
}); | ||
var parentName = keyMatch.replace('.{index}', ''); | ||
@@ -1042,0 +1067,0 @@ parentName = parentName.replace('[{index}]', ''); |
{ | ||
"name": "@alifd/field", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"description": "Fields can be used to manage data when it comes to form data manipulation and validation. After being associated with a component, the form data can be automatically written back, read, and verified.", | ||
@@ -84,3 +84,3 @@ "files": [ | ||
}, | ||
"homepage": "https://unpkg.com/@alifd/field@1.1.8/build/index.html", | ||
"homepage": "https://unpkg.com/@alifd/field@1.1.9/build/index.html", | ||
"bugs": "https://github.com/alibaba-fusion/field/issues", | ||
@@ -87,0 +87,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
1538518
4278