MODX Community

Howto get value from custom TV without EXTjs?

Hi ,

Im trying to create a custom TV following the several small examples on docs.modx.com.
I managed to create the input controller and input .tpl (its a set of radio buttons).
Now how do i get the value of the chosen radiobutton to be saved to the DB?
Im not using EXTjs.

RDG

TV handlers are usually things like MIGX. Here, do you need a form that would save to db?

and what other data do you need saved? the username?

Looking at the .tpl example at: https://docs.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/adding-a-custom-tv-type-modx-2.2

<select id="tv{$tv->id}" name="tv{$tv->id}" class="combobox"></select>
<script type="text/javascript">
// <![CDATA[
{literal}
MODx.load({
{/literal}
    xtype: 'modx-combo-template'
    ,name: 'tv{$tv->id}'
    ,hiddenName: 'tv{$tv->id}'
    ,transform: 'tv{$tv->id}'
    ,id: 'tv{$tv->id}'
    ,width: 300
    ,value: '{$tv->value}'
{literal}
    ,listeners: { 'select': { fn:MODx.fireResourceFormChange, scope:this}}
});
{/literal}
// ]]>
</script>

You can see the values are all stored in the $tv variable. e.g. $tv->id, $tv->value etc.

In this particular instance it’s putting the values into an ExtJS combobox.

You could put the same values into your own HTML or JavaScript.
ExtJS makes this kind of thing straight-forward but if you’re using your own code, there may be some extra cases you may need to cover.

Hi,
I want to be able to make my own TV without Extjs. I know how to make the HTML for it and the JS.
I just dont see how i can use an JS event to store the value to the MODX db. Or store it in some hidden INPUT or something so it can be saved. and how to set the selected state. These things all seem to be handled by Extjs so i want to know how to do this with plain HTML/JS ? so i can make any TV i swant in the future
tnx

Sorry, I read it as “get the value”.

The edit resource page is one big form that gets submitted. Do you see the inputted value from your custom TV in the browser console XHR request?

1 Like

It would be useful to see your code to pinpoint where it goes wrong, but the basic idea is that there’s an input on the page with name="tv{$tv->id}" that holds the value to be submitted. It works that way for ExtJS TVs as well as other TV types.

So if you use radio buttons, make sure they have the right name, and that should make it save.

1 Like