ldx-widgets
Version:
widgets
87 lines (77 loc) • 2.17 kB
Markdown
[<< Component Index](../README.md)
# [utils.coffee](https://github.com/tmfi/ldx-web-utilities/blob/develop/src/utils.coffee)
## updateFormValue(newData, key, value)
Upstream method used for updating a single value, returning an object created based on a key definition
### newData
**`Object`**
_Optional_
Default data object. This is the base object used to iterate upon and build the sub-properties according to the key definition
### key
**`String`**
_Required_
The key definition is provided in order to create the object structure. There are multiple ways to structure a key:
**propertyName**
```javascript
{
propertyName: 'value'
}
```
**propertyName.[0]**
```javascript
{
propertyName: [
'value',
...
...
]
}
```
**propertyName.nestedProperty**
```javascript
{
propertyName: {
nestedProperty: 'value'
}
}
```
**propertyName.nestedProperty.doubleNestedProperty**
```javascript
{
propertyName: {
nestedProperty: {
doubleNestedProperty: 'value'
}
}
}
```
**Filtering collections and injecting state properties**
You can also inject properties from the component's local state.
This can be useful when you want to filter a collection by a state variable:
**Local component state:**
```javascript
this.state = {
currentValueFilter: 888
}
```
**arrayOfValues.[{value: $currentValueFilter}]**
```javascript
arrayOfValues = [
{
value: 11
},
{
value: 888
},
{
value: 512
}
]
```
To use local state variable injection, make sure to call `updateFormValue` with the proper context applied, so state can be found: `updateFormValue.call(@, data, jsonPath, value)`
Collections can also be filtered by literal values, e.g. `55` or `'stringValue'`.
### value
**`Any`**
_Required_
The value to be assigned to the JSON object once the destination is reached