Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show/hide handlers #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions dist/editable.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ export default class App extends Component {
title="Enter username"
value="ni3galave"
handleSubmit={this.handleSubmit}
handleShow={function(arg){console.log('show', arg)}}
handleHide={function(arg){console.log('hide', arg)}}
/>
<Panel collapsible expanded={this.state.simpleTextFieldInline} >
<pre> {`<Editable
Expand Down
13 changes: 9 additions & 4 deletions libs/js/Editable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export default class Editable extends Component {
onInputChange : props.onInputChange ? props.onInputChange : null,
//handle callback if provided
handleSubmit : props.handleSubmit ? props.handleSubmit : null,
handleShow: props.handleShow ? () => props.handleShow(this) : null,
handleHide: props.handleHide ? () => props.handleHide(this) : null,
//for internal use
editable: false,
valueUpdated : false,
Expand Down Expand Up @@ -86,7 +88,7 @@ export default class Editable extends Component {

}
setEditable = (editable) => {
if(!this.state.disabled) this.setState({editable});
if(!this.state.disabled) this.setState({editable}, editable ? this.state.handleShow : this.state.handleHide);
}

onSubmit = () => {
Expand All @@ -112,10 +114,11 @@ export default class Editable extends Component {
}
}
getValueForAnchor(){
if(this.props.display){
return this.props.display(this.value);
}
if(this.value){
if(this.props.display){
return this.props.display(this.value);
} else if(this.props.seperator && _.isArray(this.value)){
if(this.props.seperator && _.isArray(this.value)){
return _.join(this.value, this.props.seperator);
}else if(_.isArray(this.value)){
return _.join(this.value, ',');
Expand Down Expand Up @@ -244,6 +247,7 @@ Editable.defaultProps = {
mode : "inline",
disabled : false,
emptyValueText : "empty",
autoFocus: true,
//depend on mode
placement : "right",
};
Expand All @@ -254,6 +258,7 @@ Editable.propTypes = {
mode : PropTypes.string,
showButtons : PropTypes.bool,
disabled : PropTypes.bool,
autoFocus: PropTypes.bool,
validate : PropTypes.func,
display: PropTypes.func,
onInputChange : PropTypes.func,
Expand Down
1 change: 1 addition & 0 deletions libs/js/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class Select extends Component {
return (
<FormGroup controlId="formControlsSelect" validationState={this.props.validation.type} >
<FormControl
autoFocus={this.props.autoFocus}
componentClass="select"
placeholder={this.props.placeholder}
bsSize="small"
Expand Down
1 change: 1 addition & 0 deletions libs/js/Text.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class Text extends Component {
return (
<FormGroup controlId="formBasicText" validationState={this.props.validation.type} key={"FormGroup"+this.props.name}>
<FormControl
autoFocus={this.props.autoFocus}
key={"form-control"+this.props.name}
type="text"
placeholder={this.props.placeholder}
Expand Down
1 change: 1 addition & 0 deletions libs/js/Textarea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class Textarea extends Component {
return (
<FormGroup controlId="formBasicTextarea" validationState={this.props.validation.type}>
<FormControl
autoFocus={this.props.autoFocus}
style={{height: '200px'}}
componentClass="textarea"
bsSize="sm"
Expand Down