How to make ajax request from custom module settings page?

Hello,

I would like to develop a custom module that requires to make ajax call from the module settings page to get some options to be loaded dynamically.

I would like to know what’s the best way to achieve that with Fastline Page Builder settings page?

Regards,

Nicolas

Hi Nicolas,

That’s a great question and one I’ll add to the custom module docs. The admin-ajax.php URL is available to you on any page where the builder is active by accessing the wpAjaxUrl variable. Using that, you can send an AJAX request like you would in any other plugin.

Here is some info from the codex on admin-ajax for your reference… http://codex.wordpress.org/AJAX_in_Plugins#Ajax_on_the_Viewer-Facing_Side

Let me know if you have any questions about that.

Thanks,
Justin

Hi Justin,

Thanks for the feedback.

So it means that I need to build the module settings page by including a file.
I was wondering if there were some mechanism to do that by registering a section with an array…

Regards,

Nicolas

Ah, sorry, I totally missed what you are trying to do. I guess I should finish my coffee before jumping into the forums :slight_smile:

We don’t currently have a mechanism for dynamic options, but I like that idea. Can you tell me…

  1. How would the AJAX call be triggered? Through a select input?
  2. Where would the options be coming from?

I’ll put some thought into this. In the meantime, you’ll have to use <YOUR_MODULE>/js/settings.js to accomplish this.

Thanks for the feedback.

Justin

Hi Justin,

  1. How would the AJAX call be triggered? Through a select input?

Yes, it would be great if an AJAX call could be triggered when a input is modified. The select input is a good favorite but it could be useful for a text input on text changed and other field types too.

  1. Where would the options be coming from?

The best would be for me to have the abilities to attach a function to this “settings field change event” where maybe the whole actulal settings values are passed. The return of this function should allow us to redefine the settings section array for example to dynamically adapt related options field for example. The possibility to return a list of suggestions when reacting to text field changed event would be great too.

I’ll use /js/settings.js in the meantime as you suggest.

Thanks,

Nicolas

Hi Nicolas,

Thanks for the feedback. It’s really helpful.

I’m actually working on an “Auto Suggest” field type now that will be a text field that pulls data from the server and provides a list of results to choose from. The builder will offer category, tag and user data options for developers. You will be able to hook into this field and customize the response.

Can you shoot me a copy of the module you are working on when you are done? I would love to see what AJAX logic you are implementing so I can look at abstracting it into a new field type.

Thanks,
Justin

Hi Justin,

The “Auto Suggest” field type you talk about is very interesting and it’s what I was planning to develop :slight_smile: I need it to build modules like posts grid, posts slider, …
So having the abilities to use your Auto Suggest field type for category and tag will be really helpful.

Do you plan to implement auto suggest field type for posts, pages, …?
Does the auto suggest field type will allow multiple selection?
Do you plan to develop modules like posts grids, posts sliders, …? And if yes, do you have already an idea of the timeline?

I’ll keep you posted if I produce something interesting.

Thanks,

Nicolas

Hi Nicolas,

I’m glad to hear that will help! I’m actually working on the post grid module right now and will be working on the post slider module after that. Here’s a sneak peek of the settings…

Do you plan to implement auto suggest field type for posts, pages, …?

I’m not sure yet. I don’t really feel it’s necessary to mix post types in the grid, so I wasn’t planning on it. What do you think about mixing post types? I think it complicates things. I’m planning on making things like categories and tags disappear if you select a post type that doesn’t support them from the drop down. I’d also like to show an auto suggest for custom taxonomies if you choose a post type that has them.

Does the auto suggest field type will allow multiple selection?

Yes

Do you plan to develop modules like posts grids, posts sliders, …? And if yes, do you have already an idea of the timeline?

I’m hoping to have the post grid done sometime next month. The query builder interface is going to be the hardest part to build, so once we have that, the post slider should go much quicker.

Justin

Hi Justin,

I’m impatient now to be able to play with the query builder you are developing :slight_smile:

I don’t really feel it’s necessary to mix post types in the grid, so I wasn’t planning on it. What do you think about mixing post types?

I don’t mean mixing post types but just have field type like the tag or category one you are working on to pick up specific posts (when Post Type = Posts) or pages (when Post Type = Pages), or custom posts…
It could be an addition for the query builder to choose specific items instead of choosing by category or tag and it could be useful to specify an exclusion list too (for example, all post with featured tag except …).

Nicolas

Hi Nicolas,

Thanks for the clarification. I’m not sure if the first version will have the ability to select specific posts, but I have thought about that and will be including it at some point. I’ll shoot you a beta of the module when it’s ready to test so you can play with it :slight_smile:

Justin