solved new value

TiG
TiG
@tig
6 years ago
184 posts
The select_and_text form field type provides a box for the user to enter a custom value. This box is always labeled 'new value' (or what is placed in lang [48]).

I would like to provide a more descriptive label (one that varies per instance) to mitigate user confusion. There does not seem to be any way to accomplish this (other than to create a new field type).

Anyone know of a way to adjust the 'new value' label per instance?


--
TiG

updated by @tig: 04/08/19 10:34:58PM
brian
@brian
6 years ago
10,148 posts
You could do this with a Core "view_results" listener that just does a straight up string replace based on the module/view - i.e.

jrCustom_view_results_listener($_data, $_user, $_conf, $_args, $event)
{
    global $_post;
    if (isset($_post['module']) && $_post['module'] == 'myCustomModule' && isset($_post['option']) && $_post['option'] == 'item_create') {
        $_data = str_replace('form_select_and_text_tag">new value', 'form_select_and_text_tag">changed value', $_data);
    }
    return $_data;
}

"item_create" would be the name of your form view function you want to change the value on. It feels like a bit of a hack but should work :)


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
TiG
TiG
@tig
5 years ago
184 posts
Brian

I agree, this is a hack but it is fail-safe. The worst case scenario is to wind up where I was. So I went ahead and implemented it. Hopefully this addresses the confusion.

To implement, I introduced a bit more surgical code that focuses on a specific field and works even if the user has customized the label. In case others wish to use this method, here is the operative function (ntCore is the the core for NT modules):

/**
 * Change the default 'new value' label to $label in a 'select_and_text' field with id of $field
 * @param  string - $content - the HTML content of a form to be displayed
 * @param  string - $field - the id of the subject 'select_and_text' field
 * @param  string - $label - the new label to replace the default of 'new value'
 * @return string - the modified content (original content if no modification made)
 */
function ntCore_relabel_new_value_field($content,$field,$label)
{ $signature = 'id="' . $field . '_select"'; // signature for field if (strpos($content, $signature) >= 0) // avoid unnecessary preg { $_ln = jrUser_load_lang_strings(); $target = $_ln['jrCore'][48]; // current label to replace $pattern = '~(.+' . $signature . '.+form_select_and_text_tag">)(' . $target . ')(<.*)~s'; $replace = '$1' . $label . '$3'; $new_content = preg_replace($pattern,$replace,$content,1); return $new_content ? $new_content : $content; } else return $content; }

Thanks again for providing critical info for me to make progress.

Happy New Year,
TiG


--
TiG
brian
@brian
5 years ago
10,148 posts
Awesome - glad this worked out :)


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags