Attaching onChange Event to TextEditor Model
New DiscussionI’m attempting to attach an onChanage event handler to a TextEditor for an MVC Model item but I’m not having any luck. Here’s the code fragment
<label for=”carrierEditor”>Carrier: </label>
@(Html.Infragistics().TextEditorFor(m => m.Carrier)
.ID(“carrierEditor”)
.PlaceHolder(“Carrier”)
.ValidatorOptions(options => options
.OnBlur(false)
.OnChange(false)
.OnSubmit(true)
.Required(true))
.AddClientEvent(“igtexteditorvaluechanged”, “function(evt, ui){ $(‘#tbsCarrier’).innerHTML = ui.value; }”)
.Render())
@(Html.ValidationMessageFor(m => m.Carrier))
This throws a javascript error in the Chrome developer tools.
I have another DOM element that I’m trying to update when the value changed event fires.
<td align=”left”><div id=”tbsCarrier”></div></td>
I tried using this:
<div class=”group-fields inline”>
<label for=”carrierEditor”>Carrier: </label>
@(Html.Infragistics().TextEditorFor(m => m.Carrier)
.ID(“carrierEditor”)
.PlaceHolder(“Carrier”)
.ClientEvents(new Dictionary<string, string>(){{ “igtexteditorvaluechanged”, “UpdateControl(this, ‘#tbsCarrier’)” }})
.ValidatorOptions(options => options
.OnBlur(false)
.OnChange(false)
.OnSubmit(true)
.Required(true))
.Render())
@(Html.ValidationMessageFor(m => m.Carrier))
</div>
That doesn’t give me a JavaScript error, but it doesn’t do anything either
I’ve tried using this script block on the page:
<script type=”text/javascript”>
$(function () {
$(“#carrierEditor”).on(“igtexteditorvaluechanged”, function (evt, ui) {
$(“#tbsCarrier”).innerHTML = ui.value;
});
$(“#contactEditor”).on(“igtexteditorvaluechanged”, function(evt, ui){
$(“#tbsCarrierContact”).innerHTML = ui.value;
});
})
function UpdateControl(controller, target) {
$(target).innerHTML = controller.value()
}
</script>
But that has no effect.
What am I missing? There doesn’t seem to be a good example that I could find.
Any help would be appreciated,
Ken