Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

"$.entwine is not a function" error with TreeMultiSelectField in a Front End Form


Go to End
Reply


2 Posts   388 Views

Avatar
benald

Community Member, 10 Posts

3 February 2017 at 4:13pm

Edited: 03/02/2017 4:23pm

I need to select multiple parent / child categories in a front end form, I am using a TreeMultiSelectField to achieve this in SilverStripe 3.5.1 and can successfully populate this dropdown in the CMS Page, but when I add to my front end form the field doesn't render and I get the following errors in the browser console:

Uncaught TypeError: Cannot read property 'msie' of undefined
    at jquery.entwine-dist.js?m=1482356614:757
    at jquery.entwine-dist.js?m=1482356614:801
(anonymous) @ jquery.entwine-dist.js?m=1482356614:757
(anonymous) @ jquery.entwine-dist.js?m=1482356614:801
TreeDropdownField.js?m=1482356614:2 Uncaught TypeError: $.entwine is not a function
    at TreeDropdownField.js?m=1482356614:2
    at TreeDropdownField.js?m=1482356614:446

This is my form

 <?php

class CreateArtifactPage extends ListPage {

    private static $db = array ( );

    private static $has_one = array(
            'LotteryFeed'	    => 'LotteryFeed',
            'ProofImage' 	    => 'Image'
    );
    
    private static $many_many = array(
            'Images'	        => 'Image'
    );
    
    private static $belongs_many_many = array(
        'BelongSections'    => 'CatalogueSection'
    );

    public function getCMSFields() {
	$fields = parent::getCMSFields();
        $internalURLField = TreeMultiSelectField::create('BelongSectionsID', 'Select Section', 'CatalogueSection');  // this works!!!!
        $fields->addFieldsToTab('Root.Main', array($internalURLField));
	return $fields;
    }

}

class CreateArtifactPage_Controller extends ListPage_Controller {
    
    private static $allowed_actions = array( 'NewArtifactForm' );

    public function NewArtifactForm() {
        
        $map = LotteryFeed::get()->map('ID','Title');

        // Create fields
        $fields = FieldList::create(
            TextField::create('Title', 'Name'),
            TextField::create('URLSegment'),
            TextField::create('Content', 'Description'),
            TreeMultiSelectField::create('BelongSectionsID', 'Select Section', 'CatalogueSection'),  // returns $.entwine errrors in the console as above
            OptionsetField::create('LotteryFeedID', 'LotteryFeed', $map, LotteryFeed::get()->first()->ID),
            TextField::create('Brand', 'Item Brand'),
            TextField::create('Year', 'Year Purchased'),
            TextField::create('Location', 'Item Location'),
            TextField::create('Price', 'Item Price'),
            FileAttachmentField::create('ProofImage', 'Proof of ownership')
                ->setThumbnailHeight(80)
                ->setThumbnailWidth(80)
                ->setMaxResolution(50000000), 
            FileAttachmentField::create('Images', 'Artifact Images')
                ->setThumbnailHeight(80)
                ->setThumbnailWidth(80)
                ->setMaxResolution(50000000), 
            CheckboxField::create('IsFeatured', 'Add item to Feature list?'),
            CheckboxField::create('EnableComments', 'Allow users to ask questions?')
        );

        // Create actions
        $actions = new FieldList(
            FormAction::create('submit', 'Create New Item')
        );

        $required = new RequiredFields('Title', 'URLSegment', 'Content', 'Price');
        $form = new Form($this, 'NewArtifactForm', $fields, $actions, $required);

        return $form;
    }
    // Write data into DataObject
    public function submit($data, $form) {
        $submission = new Artifact();
        $form->saveInto($submission);
        $submission->write();
        return $this->redirectBack();
    }

}

Can anyone help to resolve this issue?

Avatar
blueskies

Community Member, 44 Posts

30 May 2017 at 12:14am

I'm not entirely sure this would resolve your issue, because I ran into this error message in a different context (using zenvalidator, newest version, which ships with parsley 2.5 and interacts with SS's version of entwine but my site uses jquery 2+). It turns out that in my case the jquery version was so new, it no longer had browser detection built in. So I solved it by adding the jquery browser plugin as suggested through this post: https://stackoverflow.com/questions/14793331/uncaught-typeerror-cannot-read-property-msie-of-undefined