This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Adam
Adam

How can I add a custom JS file to a backend form? I need to include a google map and then pull out lat/lon which will update the related text input. The plan is to use a partial to show the map, and then the JS to update the inputs.

Cheers,

Adam

andrew
andrew

I think what you're looking for is injecting js.

Adam
Adam

Ah ok can that be used in a model partial? I thought it was just pages / layouts? Will give it a bash.

Adam
Adam

Nope doesn't work, just renders the {% put %} tag and content which makes sense as I've not added a {% scripts %} tag to the admin theme (as I don't want to mess around with that). However it does just let me put normal script tags in so I'll do that in lieu of a "proper" alternative.

Ben
Ben

Try this: In your controller add this:

public function __construct()
{
       $this->addJs('/plugins/Name/pluginame/assets/js/app.js'); //this should inject app.js
}

Last updated

Adam
Adam

Hadn't thought of that Ben, but no cigar.

Call to undefined method Illuminate\Database\Query\Builder::addJs()

Last updated

Adam
Adam

Ah I was using original version from email so was adding to model. Doing it in controller works spot on. Ta!

that0n3guy
that0n3guy

I think you could also add it to your controller update/create template.

1-8 of 8

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.