Page 1 of 1

Customizing news module backend with Jquery

Posted: Tue Feb 04, 2020 10:55 am
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?

Re: Customizing news module backend with Jquery

Posted: Tue Feb 04, 2020 6:24 pm
by rotezecke
i assume that on edit, the event is load, not change.

Code: Select all

  $('select').on('load change',function(e) { 
    //your code
  } );

Re: Customizing news module backend with Jquery

Posted: Wed Feb 05, 2020 8:24 am
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');
});