8

I was wondering if you can stop text being editable on click? I have a separate edit button to make the text editable and that's the only way that I want the user to be able to edit the text, so want to turn off the on click editing?

Any ideas?

user406307
  • 81
  • 1
  • 2

2 Answers2

4

Britt is right, add a custom event, and trigger it with a button for example. Here is some code to explain it:

The custom event:

$('#id').editable('http://www.example.com/save.php', {
    event : 'custom_event'
});

And the trigger:

<button onclick="$('#id').trigger('custom_event');">click to trigger</button>
Lutsen
  • 153
  • 1
  • 11
  • That will prevent you to allow mouseover if you use event for custom-event ? – Yugal Jindle Apr 17 '12 at 05:59
  • @Lutsen, really great solution. It took some time to understand your solution but after it, it's working like charm. I was seeking this answer since so many days (around 8 to 10 days). But then I prayed to Stackover Angel and finally I found this solution. I also thumbs up your solution. – Smile Dec 10 '13 at 09:04
2

There's an undocumented option event that you can use when you create your jEditable fields.

(It's not actually undocumented but it's just mentioned off-hand in one sentence on the jEditable docs page.)

You can use it to change the event that makes the field editable. You can use any jquery event, even custom events.

For example, on my project I created an edit.mode event that makes the field editable which I can then trigger however I like, with a button, a hotkey, whatever.

britt
  • 325
  • 1
  • 6
  • A am appreciating your answer too for great explanation which I couldn't understood while reviewing doc for jEditable. – Smile Dec 10 '13 at 09:05
  • I am a little confused as to what the 'event' value represents. Is it a function name? – akeane Oct 21 '15 at 09:39
  • Ignore the above question... it was stupid and I understand what it is now. Sorry... I asked before I thought... happens sometimes. There was something missing which was the unbinding part that I was interested in but found it later (sort of like a toggle). – akeane Oct 21 '15 at 09:53