Skip to content

Commit

Permalink
- Fixes to the select fields
Browse files Browse the repository at this point in the history
  • Loading branch information
josebalius committed Jul 8, 2014
1 parent 4a02b64 commit 5d12327
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
31 changes: 27 additions & 4 deletions build/js/ngReactGrid-0.6.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,23 @@ var ngReactGridSelectFieldComponent = (function() {
}
};
},
handleChange: function(e) {
var value = e.target.value;
this.props.updateValue(value);
this.setState({
defaultValue: {
id: value
}
});
},
componentWillReceiveProps: function(nextProps) {
this.setState({
defaultValue: nextProps.value
defaultValue: nextProps.value || {}
});
},
componentWillMount: function() {
this.setState({
defaultValue: this.props.value
defaultValue: this.props.value || {}
});
},
render: function() {
Expand All @@ -594,7 +603,7 @@ var ngReactGridSelectFieldComponent = (function() {
});

return (
React.DOM.select( {className:"ngReactGridSelectField", value:this.state.defaultValue.id},
React.DOM.select( {className:"ngReactGridSelectField", value:this.state.defaultValue.id, onChange:this.handleChange},
options
)
)
Expand Down Expand Up @@ -1493,14 +1502,28 @@ var ngReactGridSelectFieldFactory = function($rootScope) {
this.record = record;
this.field = field;
this.updateNotification = updateNotification;
this.referenceData = referenceData;

var value = NgReactGridReactManager.getObjectPropertyByString(this.record, this.field);

return ngReactGridSelectFieldComponent({value: value, updateValue: this.updateValue.bind(this), referenceData: (referenceData || [])});
};

ngReactGridSelectField.prototype.updateValue = function(newValue) {
NgReactGridReactManager.updateObjectPropertyByString(this.record, this.field, newValue);

var updateValue = {};

for(var i in this.referenceData) {
var option = this.referenceData[i];

if(option.id == newValue) {
updateValue = option;
}
}

console.debug(this.record, this.field, updateValue);

NgReactGridReactManager.updateObjectPropertyByString(this.record, this.field, updateValue);

if(this.updateNotification) {
if($rootScope.$$phase) {
Expand Down
Loading

0 comments on commit 5d12327

Please sign in to comment.