Open gchokeen opened 9 years ago
I did some work around to achieve above request, please check and tell me this can be implemented.
$(function () {
var clone = $("#clone");
clone.click(function () {
alert("clicked");
var e = $.Event("before_clone.cloneya");
$(this).triggerHandler(e);
if (e.isDefaultPrevented()) {
return;
}
alert("cloned");
});
clone.on("before_clone.cloneya", function (e) {
if(!confirm('Are you sure, you want to clone this?')){
e.preventDefault();
}
});
});
I created the js fiddle demo here
This is fine, but you'd also need to write the unit tests for validation. Let me know if you need help with that.
I'm keeping it for a future 1.1.0 release. I need to write more tests for nested cloning and deleting. This would've saved me #41
@gchokeen I wanted to discuss the flow. For example, when cloning the following events can be prevented
before_clone.cloneya
after_clone.cloneya
before_append.cloneya
after_append.cloneya
So, if 1 is prevented, 2, 3 & 4 would also need to be prevented. Same way, if 2 is prevented, 3 and 4 would also need prevention. I want to avoid too many nested if statements.
@actual-saurabh, I created validation branch to implement this feature. I will implement and update soon.
I think once before_clone.cloneya event prevented all other follow up event's should not trigger. Since we return if event prevented.
👍
Form validation is taking important role in all the applications. So I think cloneya should give the control to user for validating form.
Case:
I don't see anyway to achieve this on before_clone or before_delete event callback.
Can return false do the trick ?