N
N
Nikolai Novosad2017-03-21 00:01:55
JavaScript
Nikolai Novosad, 2017-03-21 00:01:55

Clone TinyMCE?

Hello.
I have this markup for displaying a form in job.tpl

<?php foreach($vacancies as $key_vacancy => $vacancy): ?>
                    <div class="field-group">
                        <a href="#" class="buttonGray buttonRight deleteVacancy">Delete Vacancy</a>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="input-title"><?php echo $entry_title; ?></label>
                            <div class="col-sm-10">
                                <input type="text" name="vacancy[<?php echo $key_vacancy; ?>][title]" value="<?php echo $vacancy['title']; ?>" placeholder="<?php echo $entry_title; ?>" id="input-title" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="input-supervisor"><?php echo $entry_supervisor; ?></label>
                            <div class="col-sm-10">
                                <input type="text" name="vacancy[<?php echo $key_vacancy; ?>][supervisor]" value="<?php echo $vacancy['supervisor']; ?>" placeholder="<?php echo $entry_supervisor; ?>" id="input-supervisor" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="input-duties"><?php echo $entry_duties; ?></label>
                            <div class="col-sm-10">
                                <textarea name="vacancy[<?php echo $key_vacancy; ?>][duties]" placeholder="<?php echo $entry_duties; ?>" id="input-duties" class="form-control"><?php echo $vacancy['duties']; ?></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="input-requirements"><?php echo $entry_requirements; ?></label>
                            <div class="col-sm-10">
                                <textarea name="vacancy[<?php echo $key_vacancy; ?>][requirements]" placeholder="<?php echo $entry_requirements; ?>" id="input-requirements" class="form-control"><?php echo $vacancy['requirements']; ?></textarea>
                            </div>
                        </div>
                    </div>
<?php endoreach; ?>


This is where js is included.
<script src="//cloud.tinymce.com/stable/tinymce.min.js"></script>
    <script>tinymce.init({ selector:'textarea' });</script>
    <script type="text/javascript" src="view/javascript/repeat-fields.js"></script>


The contents of the repeat-fields.js file to clone:
var attrs = ['name'];
function resetAttributeNames(section) {
    var tags = section.find('input, textarea'), idx = section.index();
    tags.each(function() {
        var $this = $(this);
        $.each(attrs, function(i, attr) {
            var attr_val = $this.attr(attr);
            if (attr_val) {
                $this.attr(attr, attr_val.replace(/\[(\d+)\]/,'['+ idx +']'));
            }
        })
    });
}

$('.addVacancy').click(function(e){
    e.preventDefault();
    var lastRepeatingGroup = $('.field-group').last();
    var cloned = lastRepeatingGroup.clone(true);
    $('input[type="text"]', cloned).val("");
    cloned.insertAfter(lastRepeatingGroup);
    resetAttributeNames(cloned);
});


When cloning, TinyMCE appears, but I can't edit anything.
Please tell me how to properly clone TinyMCE.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question