Admin options and validation callback questions


Well-known member
Ugh, this may be really showing my stupidity, but if somebody could point me to an addon that has uses this, or just point me in the right direction, I'd greatly appreciate it.

I have 2 issues with an addon I'm creating, and it's basic options.

The first issue is that I'd like to have an input box that the user enters a key into, and after they do that, the option isn't displayed anymore on the addon's options page, but there is a checkbox to reset the key, if needed.

I can create the input box easily enough, and I have an admin template created to 1) display a message if the key is already entered, or 2) display the empty input box.

I have a separate checkbox option to "reset" the key that is displayed if the key already exists.

The problem I have is that I can't seem to find out how to reset the key value to null if the checkbox is selected.

The way I thought I'd have to do it is by using a validation callback on the checkbox to set the key to null if the box is checked, but do I do that via the datawriter?

Or do I need to use the options preSave method to change the value of the key somehow when the checkbox is checked?

The second issue, and this might be pretty ignorant.

I'm using this as the admin template for the above "key" option. It displays a phrase that they key exists if a variable is set from the renderOption method, otherwise it displays the option.
<xen:if is="{$preparedOption.keyexists}">
    <div style="text-align: center;">
             {xen:phrase option_theaddon_KeyExists} {$preparedOption.option_value}

<xen:else />

    <xen:textboxunit label="{$preparedOption.title}" 
            <xen:explain>{xen:raw $preparedOption.explain}</xen:explain>
        <input type="hidden" name="{$listedFieldName}" value="{$preparedOption.option_id}" />
        {xen:raw $editLink}
The problem with this is that if the message is displayed, there is no edit link to the right of the option, but the editlink is displayed when the actual textbox is displayed. I assume I need to include the "{xen:raw $editLink}" with the display of the message, but that would require creating the textboxunit, right?

Is there a better way to display the edit link for the text input box on the right, even though I'm not displaying the text input box.