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

onChange: prevent certain input #8

Closed
harrygates opened this issue May 12, 2012 · 4 comments
Closed

onChange: prevent certain input #8

harrygates opened this issue May 12, 2012 · 4 comments

Comments

@harrygates
Copy link

How would I go about allowing only numbers to be input? I tried the following in the onChange event, but I'm not sure how to call the line: "this.editproxy.finishEditing(true);" or if there is maybe a better way.

handsontable is awesome and I'd like to thank you for creating such a lightweight javascript spreadsheet!

onChange: function (data) {
if (first) {
first = false;
return;
}
$("#dataTable-console").text(JSON.stringify(data));
var newValue = data[0][3];
if(isNaN(newValue)) {
alert("only numbers allowed!");
alert(data[0][0] + '\t' + data[0][1] + '\t' + data[0][2]);
this.editproxy.finishEditing(true);
}
}

@harrygates
Copy link
Author

I was able to achieve the desired result using the following:

onChange: function (data) {
if (first) {
first = false;
return;
}
$("#dataTable-console").text(JSON.stringify(data));
var newValue = data[0][3];
alert(newValue);
if(isNaN(newValue)) {
alert("only numbers allowed!");
alert(data[0][0] + '\t' + data[0][1] + '\t' + data[0][2]);
$("#dataTable").handsontable("setDataAtCell",data[0][0], data[0][1], data[0][2]);
}
}
});

@harrygates
Copy link
Author

The latest code changes seems to have broken the "setDataAtCell" method above. The data remains what was entered, even with text.

@warpech
Copy link
Member

warpech commented May 22, 2012

You are right gatesh, thanks for noticing. I submitted a fix. Please check again

@warpech warpech closed this as completed May 22, 2012
@harrygates
Copy link
Author

Thanks, warpech! Works great now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants