Skip to content

Commit

Permalink
Merge pull request #538 from rodriguezc/event-normalization
Browse files Browse the repository at this point in the history
Event normalization for React Form libraries
  • Loading branch information
cagataycivici authored Sep 20, 2018
2 parents 41fa890 + f542224 commit 762d108
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 27 deletions.
10 changes: 9 additions & 1 deletion src/components/autocomplete/AutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,18 @@ export class AutoComplete extends Component {
}

updateModel(event, value) {
const resolvedFieldData = this.props.field ? ObjectUtils.resolveFieldData(value, this.props.field) : undefined;
if(this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: value
value: value,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: resolvedFieldData ? resolvedFieldData: value
}
});
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/components/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,14 @@ export class Calendar extends Component {
if (this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: value
value: value,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value
}
});
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/components/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ export class Checkbox extends Component {
this.props.onChange({
originalEvent: e,
value: this.props.value,
checked: !this.props.checked
checked: !this.props.checked,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
type: 'checkbox',
name: this.props.name,
id : this.props.id,
value: this.props.value,
checked: !this.props.checked,
}
});

this.input.checked = !this.props.checked;
Expand Down
18 changes: 16 additions & 2 deletions src/components/chips/Chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ export class Chips extends Component {
if (this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: values
value: values,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value : values
}
});
}
}
Expand Down Expand Up @@ -122,7 +129,14 @@ export class Chips extends Component {
if (this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: values
value: values,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value : values
}
});
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/components/colorpicker/ColorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ export class ColorPicker extends Component {
onChange(value) {
if(this.props.onChange) {
this.props.onChange({
value: value
value: value,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value
}
})
}
}
Expand Down
27 changes: 24 additions & 3 deletions src/components/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,14 @@ export class Dropdown extends Component {
onEditableInputChange(event) {
this.props.onChange({
originalEvent: event.originalEvent,
value: event.target.value
value: event.target.value,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value : event.target.value,
}
});
}

Expand Down Expand Up @@ -304,7 +311,14 @@ export class Dropdown extends Component {
clear(event) {
this.props.onChange({
originalEvent: event,
value: null
value: null,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value : null
}
});
this.updateEditableLabel();
}
Expand All @@ -316,7 +330,14 @@ export class Dropdown extends Component {
this.updateEditableLabel(event.option);
this.props.onChange({
originalEvent: event.originalEvent,
value: this.props.optionLabel ? event.option : event.option.value
value: this.props.optionLabel ? event.option : event.option.value,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value : this.props.optionLabel ? event.option : event.option.value,
}
});
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/components/inputmask/InputMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,14 @@ export class InputMask extends Component {
var val = this.props.unmask ? this.getUnmaskedValue() : e.target.value;
this.props.onChange({
originalEvent: e,
value: (this.defaultBuffer !== val) ? val : ''
value: (this.defaultBuffer !== val) ? val : '',
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value : (this.defaultBuffer !== val) ? val : '',
}
})
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/components/inputswitch/InputSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ export class InputSwitch extends Component {
if (this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: !this.props.checked
value: !this.props.checked,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: !this.props.checked,
}
});
}
}
Expand Down
18 changes: 16 additions & 2 deletions src/components/listbox/ListBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,14 @@ export class ListBox extends Component {
if(valueChanged) {
this.props.onChange({
originalEvent: event,
value: value
value: value,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value
}
});
}
}
Expand All @@ -171,7 +178,14 @@ export class ListBox extends Component {
if(this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: value
value: value,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value
}
});
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/components/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ export class MultiSelect extends Component {
if(this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: value
value: value,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value
}
});
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/components/radiobutton/RadioButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ export class RadioButton extends Component {
this.props.onChange({
originalEvent: e,
value: this.props.value,
checked: !this.props.checked
checked: !this.props.checked,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: this.props.value,
}
});

this.input.checked = !this.props.checked;
Expand Down
18 changes: 16 additions & 2 deletions src/components/rating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ export class Rating extends Component {
if (!this.props.readonly && !this.props.disabled && this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: i
value: i,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: i
}
});
}

Expand All @@ -53,7 +60,14 @@ export class Rating extends Component {
if (!this.props.readonly && !this.props.disabled && this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: null
value: null,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: null
}
});
}

Expand Down
9 changes: 8 additions & 1 deletion src/components/selectbutton/SelectButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ export class SelectButton extends Component {
if(this.props.onChange) {
this.props.onChange({
originalEvent: event.originalEvent,
value: newValue
value: newValue,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: newValue,
}
});
}
}
Expand Down
18 changes: 16 additions & 2 deletions src/components/slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,14 @@ export class Slider extends Component {
if (this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: this.values
value: this.values,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: this.values,
}
})
}
}
Expand All @@ -219,7 +226,14 @@ export class Slider extends Component {
if (this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: this.value
value: this.value,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: this.value,
}
})
}
}
Expand Down
38 changes: 33 additions & 5 deletions src/components/spinner/Spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ export class Spinner extends Component {
if (this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: newValue
value: newValue,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: newValue
}
});
}
}
Expand Down Expand Up @@ -239,7 +246,14 @@ export class Spinner extends Component {
if (this.props.onChange) {
this.props.onChange({
originalEvent: event,
value: event.target.value
value: event.target.value,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: event.target.value
}
});
}
}
Expand All @@ -248,15 +262,29 @@ export class Spinner extends Component {
DomHandler.removeClass(this.element, 'p-inputwrapper-focus');

if (this.props.onChange) {
const parsedValue = this.parseValue(event.target.value);
this.props.onChange({
originalEvent: event,
value: this.parseValue(event.target.value)
value: parsedValue,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
value: parsedValue,
}
});
}

if (this.props.onBlur) {
this.props.onBlur({
event: event
event: event,
stopPropagation : () =>{},
preventDefault : () =>{},
target: {
name: this.props.name,
id : this.props.id,
}
});
}
}
Expand Down Expand Up @@ -334,4 +362,4 @@ export class Spinner extends Component {
</span>
);
}
}
}
Loading

0 comments on commit 762d108

Please sign in to comment.