Jump to content

Recommended Posts

I'm looking to do a specific type of module. I want to use the field-typemulti fieldtype. So what I want to accomplish is
the first field part stores a category (movies, books, etc.). The Second input field would need to be an AJAX lookup that would let me choose the ID of that book so I can take it and save it into my post. So let's just say the thing I'm pulling from is IMDB, I'll choose the movie category, then On the lookup get a list of movies based on a search. IF you can point me and help me out with this i'd greatly appreciate it!

Share this post


Link to post
Share on other sites

I would say a ProcessModule for the AJAX request. That module should extend Process and Make sure the config array contains 'permission' => 'page-edit'

  • Like 1

Share this post


Link to post
Share on other sites

No need for a extra Process page. Just send a ajax POST/GET request with a special key you recognize in your module's init(), do the work and send back an result.

  • Like 3

Share this post


Link to post
Share on other sites
On 07/07/2016 at 5:09 PM, Soma said:

No need for a extra Process page. Just send a ajax POST/GET request with a special key you recognize in your module's init(), do the work and send back an result.

Hi @Soma. Could you please elaborate on how to do this? I don't quite follow what is being sent where :). Thanks..

Share this post


Link to post
Share on other sites

Something along the way

public function init(){
	if($this->config->ajax && $this->input->InputfieldMyAjaxBomb){
		// handle your ajax request
		header('Content-Type: application/json');
		echo "{'yo':'yo'}";
		exit;
	}
}

.. in your Inputfield init(). Then you can make a post or get AJAX request to any backend or public url the current url containing the key InputfieldMyAjaxBomb=1.

Edit: Originally I didn't really mean that there's "no need". Well, of course a hidden admin ProcessPage bundled with your module is also good and honestly maybe even the more correct way. But It's easy to implement and test things out too.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Soma. I have been doing it the 'hidden-admin-page-way'...as you suggested way back in this thread :). Good to know there's other ways too.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ICF Church
      Hi 👋
      Anyone else having this problem?
      Requirements:
      - Repeater (matrix & normal) with mutlilanguage fields (text, textarea…) 
      - Backend language set to something other than default (ie. German) 
      Reproduce:
      - Add a new repeater Item (ajax, I found no way to possible to disable it with matrix)

      (Notice how the default language tab is active instead of the backend language…)
      - Write something into the (default language) field
      - Try to save, if field is required, this will not work. If not required, then when reloading, the content will be inside the backend language field, instead of the default language field who was (presumably) active
      Analysis:
      When  loading  a new repeater element with ajax, the default langue tab is active, but the backend language inputfield is visible (with no visual indication). When writing into the field, it will populate the backend language. When manually clicking on the default language tab (which is already active), the field will switch to the actual default language field (which is [now] empty) (that can now be populated…)
      Also Notice, the labels of the elements to be added are in default language as well instead of the translated label (images instead of Bilder)…
      ProcessWire 3.0.148, Profields 0.0.5…
      Is it my system configuration, or does anyone else have the same issue? This is a screen recording of the problem:
      Issue: https://github.com/processwire/processwire-issues/issues/1179

      Screen Recording 2020-02-25 at 14.18.31.mov
    • By michelangelo
      Hello there,
      I am building my website, which has a dozen projects with 10 images each. Basically, I need a filtering system but built in the most efficient and user-friendly way. You can see below that the images flow sideways so being hidden, JS lazy loading was a good tool, but I just wanted to try AJAX. Is it fit for this purpose or it's more for dynamic content?
       

    • By Lmwt
      Hi there,
      I am new to PW but already very convinced. I need to build a dropdown button to browse in a collection of authors by country and language. The dropdown should be editable in the BACK and displayed on the same as the authors collection. I tried my luck with "PageField Creator" but I don't know how to display the dropdown, I simply used: 
      "$content .=$page->Land;" (the name of the select field)
      but nothing is displayed...
      I see there is a 2nd module out there to achieve this : "Select Options Fieldtype". I am not sure what is the difference, anyone has a tip?
      And a clear tutorial with the necessary steps to build this? I am a bit confused which should be the parent template or page, if it should have a file or not...
      Thanks a lot in advance!
    • By Noel Boss
      👋 PW Pros…
      I have some hooks that I need to bind at the init phase (or even __construct) and I was wondering, and I couldn't find a good and simple way to determine if I'm in the admin. Would be nice if there is a reliable short option to do so, but I can't seem to find one… Is there a coherent way to tell this no matter where I am?
      Right now, I use the following method inside one of my modules:
      public function isAdmin($page = null) { if ( strpos($this->input->url, $this->urls->admin) !== false || $this->process instanceof ProcessPageList || $this->process instanceof ProcessPageEdit || ($page instanceof Page && $page->rootParent->id == $this->config->adminRootPageID) ) { return true; } return false; } @ryan wouldn't it be nice to have something like wire()->isAdmin(); like wire()->user->isLoggedin(); to tell if we are in admin – very early on (probably even in __construct() phase of modules?
×
×
  • Create New...