简体   繁体   中英

How do I update a textarea field using ckeditor with jquery?

So I am using Drupal and I have a field which is a textarea with ckeditor enabled on it.

For some reason I can't get jquery to update the textarea. If I disabled ckeditor on that field, ie it just shows the standard textarea without the ckeditor loaded, the below code works. When I re-enable the ckeditor tool on this field, the below code appears to do nothing to the field.

Any ideas how I can get this to work? What changes do I need to make to my code to get it to play nice with ckeditor being enabled?

function updateAddressFields() {
     if(place.opening_hours.weekday_text != undefined){
         $('#edit-field-operation-hours-0-value').val('');
         for (i = 0; i < place.opening_hours.weekday_text.length; i++) { 
            var temp = place.opening_hours.weekday_text[i] + '\n';
            var curValue = $('#edit-field-operation-hours-0-value').val();
            var newValue = curValue + temp; 
            $('#edit-field-operation-hours-0-value').val(newValue);   
         }
     }
}

Here is a copy of the HTML source that is loaded when I enable CKeditor on the field:

<div class="form-item" id="edit-field-operation-hours-0-value-wrapper">
 <label for="edit-field-operation-hours-0-value">Operation Hours: </label>
 <textarea cols="60" rows="5" name="field_operation_hours[0][value]" id="edit-field-operation-hours-0-value"  class="form-textarea resizable ckeditor-mod"></textarea>
</div>
<div class="textarea-identifier description">CKEditor: the ID for <a href="/admin/settings/ckeditor">excluding or including</a> this element is <em>newsflash:world_listing@node/add/world-listing.edit-field-operation-hours-0-value</em>.</div><ul class="tips"><li>Allowed HTML tags: &lt;ul&gt; &lt;ol&gt; &lt;li&gt; &lt;dl&gt; &lt;dt&gt; &lt;dd&gt; &lt;p&gt; &lt;br&gt;</li><li>Lines and paragraphs break automatically.</li></ul><p><a href="/filter/tips">More information about formatting options</a></p></fieldset>

I am pretty sure that ckeditor replaces your textarea with it's own field. Try to inspect the field when ckeditor is loaded and see if it still have the selector you are expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM