Customizing news module backend with Jquery

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Sendlingur
Forum Members
Forum Members
Posts: 57
Joined: Wed Aug 08, 2018 4:59 pm

Customizing news module backend with Jquery

Post by Sendlingur »

I'm having a slight problem with my news module back-end.

I've been customizing the "editarticle.tpl" so it will show/hide custom fields upon category selection.

It works fine when I create a new article in that specific category.(then the custom fields appears)

But if I want to edit the article, the custom fields are not showing.
To see the custom fields when I'm editing I have to select some other category (for example "General") and then select the previous category ( for example "CustomCategory"), then the custom fields are shown and I can edit them.

My Jquery is quite simple for this.
The custom fields are wrapped in <div id="cf_group">

And then there is this Jquery to show/hide the custom fields depending on witch category is selected.

Code: Select all

 $('select').change(function() {
  if ($(this).val() == 4) {
    $('#cf_group').show();
  } else {
    $('#cf_group').hide();
  }
});
As I said before this is working nicely when I create new article, but if I want to edit an article witch have the category with "option value = =4" (the one with all the custom fields). I first have to select another category and then the "option value = =4" category to see the custom fields.

What I want to be able to do is Just edit the articles without having to toggle between categories to edit the custom fields for the articles that are assign to the category with "option value = =4".

Can some one help me with this?
User avatar
rotezecke
Power Poster
Power Poster
Posts: 369
Joined: Fri Apr 18, 2008 9:34 pm
Location: Nimbin, Australia

Re: Customizing news module backend with Jquery

Post by rotezecke »

i assume that on edit, the event is load, not change.

Code: Select all

  $('select').on('load change',function(e) { 
    //your code
  } );
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Customizing news module backend with Jquery

Post by calguy1000 »

if changing a category works fine to hide/show various fields... then when a page loads you should trigger the change event

Code: Select all

$(function(){
    $('selector').trigger('change');
});
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “CMSMS Core”