Template variables resetting

Summary

Some template variables successfully save, but if I return to the Resource afterwards to make additional changes, they now appear empty. Saving with these empty fields then removes any set values.

Step to reproduce

  1. Open Resource using Template Variables
  2. Set template variable
  3. Observe it is correctly set in the page
  4. Navigate away
  5. Return to resource
  6. Observe variables are now empty
  7. Saving now clears template variables

Observed behaviour

Template variables are now empty

Expected behaviour

Template variable should retain its previous settings

Environment

  • MODX 3.1.2-pl
  • Apache
  • MariaDB 11.4
  • Running on cPanel
  • Google Chrome

Does this happen with all the template variables or just the ones with a certain “Input Type”?
Does the same happen with normal resource fields (like pagetitle, etc.) or only with TVs?


Just to make sure I understand the issue correctly:
You can still set the TV values and these values get stored in the database (table modx_site_tmplvar_contentvalues) and are visible on the front-end (with tags like [[*tv_name]]).

But when you reload the resource in the manager, the input fields for the TVs are empty?

It happens with some template variables which use the same types as others, but some have this issue.

And yep, the template variables appear to work fine until a reload when they are then emptied - if the user then makes a change and saves the data is lost.

Hasn’t appeared to affect built in variables yet as far as I can tell.

Is it possible to provide more specific information?
What TV input types are affected?
Does the issue only occur with certain values? Maybe values that contain unusual characters (e.g. umlauts, cyrillic)?


Also, are there any plugins on your system that run on the events OnResourceTVFormPrerender or OnResourceTVFormRender?
Under :gear: → “System Settings” → tab “System Events” you can see what plugins run on what event. Use the “Search” field to filter by the event name and then check the column “Plugins”.

Sure, no problem!

Known affected TV types:

  • Text
  • Listbox (Multi-Select)

Values are all standard Latin characters with no or minimal punctuation. I have used HTML in other TV’s but those TV’s have not had problems saving.

OnResourceTVFormPrerender doesn’t have an entry in System Events for me, and OnResourceTVFormRender has no plugins that run on that event.

In terms of packages, I’m running:

  • Ace
  • AjaxForm
  • BigBrother
  • CacheClear
  • CSRF Helper
  • FormIt
  • Guzzle7
  • QuickEmail
  • VersionX

Apologies for the issue, it could be simply a first time user problem!

Are any plugins connected to events related to resources, like OnDocFormSave?

It’s very weird.

MODX 3.1.2-pl has been released almost 2 months ago now, and if there was a general issue with loading the TV values, this would be immediately obvious on almost every MODX installation. But I haven’t seen this issue before, here in the forum or on Github, and I can’t reproduce it myself.

There must be something unique occurring on your system, but I have no idea what.

Does the same issue happen if you use another browser? Maybe a browser plugin is interfering?


When you open the “Network” tab in the developer tools of the browser and then reload the MODX resource (manager/?a=resource/update&id=...), can you find the information for the TVs in the response?

There should be an HTML <input> tag for every TV in the response with the ID and name equal to tv + ID of the template variable. For example a TV of “input type”= text with the ID = 3 would look like this:

<input id="tv3" name="tv3"
    type="text" class="textfield"
    value="my tv value"
    tvtype="text"
/>

Is the value attribute already empty in the response?


The problem doesn’t seem to be the saving of the TV values, but rather loading them.
So if a plugin is interfering, then it’s more likely an event like OnDocFormRender or OnDocFormPrerender (besides OnResourceTVFormPrerender and OnResourceTVFormRender I mentioned before).
But none of the listed extras that are installed seem to be ‘suspicious’.

Is this only happening since you upgraded to 3.1.2, or was it happening before? (Or is this a new site in 3.1.2?)

Are there any errors in the MODX log (Reports → Error Log)?

The only plugin that uses OnDocFormSave is VersionX, however I did attempt to disable and it didn’t have any apparent effect.

Appears to be empty in the response, here’s part of the response for context:

        <div class="modx-tv-type-listbox-multiple x-form-item x-tab-item alt modx-tv tv-last" id="tv12-tr">
        <label for="tv12" class="x-form-item-label modx-tv-label">
            <div class="modx-tv-label-title">
                                <span class="modx-tv-caption" id="tv12-caption">group</span>
            </div>
            <a class="modx-tv-reset" id="modx-tv-reset-12" title="Set to Default"></a>
                    </label>
                <div class="x-form-element modx-tv-form-element">
            <input type="hidden" id="tvdef12" value="" />
            <select id="tv12" name="tv12[]" multiple="multiple" onselect="if (!window.__cfRLUnblockHandlers) return false; MODx.fireResourceFormChange();" onchange="if (!window.__cfRLUnblockHandlers) return false; MODx.fireResourceFormChange();" size="8" data-cf-modified-8cc7e67e0a4ed4e95ccf57c3-="">
            <option value="Programming,"  selected="selected">Programming</option>
            <option value="2D Art," >2D Art</option>
            <option value="3D Art," >3D Art</option>
            <option value="UI/UX," >UI/UX</option>
            <option value="Design," >Design</option>
    </select>```

Fresh new install, I’m a first time user so it may be user error hahaha

No it’s not empty! This is a <select> (probably from a TV of input type “Listbox (Multi-Select)”) and the Option Programming is selected (selected="selected").


I’m also a bit confused why all the option values contain a comma at the end ( → "Programming,", "2D Art,", etc.). What are your settings for this TV (especially “Dropdown List Options”)?

1 Like

The reason they have a comma is because I used them to generate a CSV for a snippet for categorisation - which it turns out was the issue! Removing them fixed the problem.

Just in case anyone runs into this in the future, the proper way of generating a CSV is via the Output Options to set a delimiter.

Now have a functional site! :tada:
(https://binaryspiders.com/)

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.