Hi!
I’m making a site where I make a huge use of TVs to store additional informations (eg. about cities, tags etc.) and for a long time I’ve tried to force NewsEditor to "accept" my TVs. I didn’t want to make additional database table to store these information because I use tagLinks on these fields.
Finally I came to such a ’conclusion’:
First of all put this in <head> of where your NewsEditor is:
<script type="text/javascript">
function submitform(FormName) {
var res = $('result_' + FormName).empty().addClass('ajax-loading');
$(FormName).send({
update: res,
onComplete: function() {
res.removeClass('ajax-loading');
}
});
}
</script>
<style type="text/css">
.ajax-loading { background: url(/path/to/your/ajax-loader.gif) no-repeat left; }
</style>
Add also a link to mootools.js if you’re not using AjaxSearch.
Then put this into a snippet (in my example [[tvForms]]):
<?php
// $tvs - comma-separated list of TVs to build forms for
// $labels - pipe | - separated list of labels for TVs
// $action - target of action=""
$tv_list = explode(',',$tvs);
$label_list = explode('|',$labels);
$tv_values = $modx->getTemplateVarOutput($tv_list,$_REQUEST['editid']);
$where = '';
for($i=0;$i<count($tv_list);$i++)
{
if($i == 0)
$where .= 'name = \''.$tv_list[$i].'\'';
else
$where .= ' OR name = \''.$tv_list[$i].'\' ';
}
$result = $modx->db->select('id, name',$modx->getFullTableName('site_tmplvars'),$where);
while($row = mysql_fetch_array($result))
{
$id = $row['id'];
$name = $row['name'];
$tv_ids[$name] = $id;
}
for($i=0;$i<count($tv_list);$i++)
{
$name = $tv_list[$i];
echo '<p><form id="tv-form-'.$i.'" action="'.$action.'" onchange="submitform(\'tv-form-'.$i.'\')">
<input type="hidden" name="id" value="'.$tv_ids[$name].'" />
<input type="hidden" name="docid" value="'.$_REQUEST['editid'].'" />
<label for="content">'.$label_list[$i].'</label><br />
<input type="text" name="content" value="'.$tv_values[$name].'" id="tv-input-'.$i.'" />
<span id="result_tv-form-'.$i.'"> </span></form></p>';
}
?>
Then create a NULL template (containing
only [*content*]). Now you have to create other snippet to parse the forms. I call it [[tvFormsParse]].
<?php
if($modx->db->update('value = \''.$_POST['content'].'\'', $modx->getFullTableName('site_tmplvar_contentvalues'), 'tmplvarid = '.$_POST['id'].' AND contentid = '.$_POST['docid']) != 0)
echo '<img src="/path/to/your/success.gif" />';
else
echo '<img src="/path/to/your/failure.gif" /><br />'.mysql_errno().': '.mysql_error();
?>
And we’re almost done

Now you create a document with the NULL template containing
And finally, in a place where you want your text inputs to be displayed you put:
[!tvForms? &tvs=`cityOfBirth,nicknames` &labels=`City where he was born:|Nicknames from high school:` &action=`path to a document you created in previous step` !]
This have to be in the document, where NewsEditor is also called.
&tvs are comma-separated (no spaces), &labels are ’|’ (pipe?) separated. These two have to be in the same order (first from &tvs goes with the firs from &labels)
And enjoy your brand new text inputs updating informations immediately after editing them!
I know it’s quite complex and inflexible, but maybe will give someone an idea (just like I needed it few day ago

).
Limitations:
- handles only text inputs (I didn’t need any other and as far as I know there is already one modification to work with checkboxes)
- work only with editing files, not with creating new ones