Example #1
0
    /**
     * Return the HTML/script required for this control.  Do it only once.
     * @return string The HTML/javascript required for this control.
     */
    public function pre_out()
    {
        $out = '';
        if (!FormControlTextMulti::$outpre) {
            FormControlTextMulti::$outpre = true;
            if (is_array($this->value)) {
                $fieldcount = count($this->value);
            } else {
                $fieldcount = 0;
            }
            // translatable strings
            // very bad practice but the below code is just horrible to read already and heredoc does not support method calls
            $removeitem = _t('Remove item');
            $remove = _t('[remove]');
            $removethisitem = _t('Remove this item?');
            $out .= <<<JSCODE
\t\t\t\t<script type="text/javascript">
\t\t\t\tcontrols.textmulti = {
\t\t\t\t\tadd: function(e, controlname){
\t\t\t\t\t\t\$(e).before('<div><input type="text" name="' + controlname + '[]"> <a href="#" onclick="return controls.textmulti.remove(this);" title="{$removeitem}" class="textmulti_remove">{$remove}</a></div>');
\t\t\t\t\t\treturn false;
\t\t\t\t\t},
\t\t\t\t\tremove: function(e) {
\t\t\t\t\t\tvar item = \$(e).prev();
\t\t\t\t\t\tif (confirm("{$removethisitem} " + item.val())) {
\t\t\t\t\t\t\titem.parent().remove();
\t\t\t\t\t\t}
\t\t\t\t\t\treturn false;
\t\t\t\t\t},
\t\t\t\t}
\t\t\t\t</script>
JSCODE;
        }
        return $this->controls_js($out);
    }
Example #2
0
    public function pre_out()
    {
        $out = '';
        if (!FormControlTextMulti::$outpre) {
            FormControlTextMulti::$outpre = true;
            $out = <<<TAGS_PRE_OUT
<script type="text/javascript">
\$(function(){
\t\$('input.tags_control').each(function(){

\t\tfor(var z in tc_tags=\$(this).val().split(/\\s*,\\s*/)) {
\t\t\ttc_tags[z]=tc_tags[z].replace(/^(["'])(.*)\$/, '\$2');
\t\t}
\t\tconsole.log(tc_tags);

\t\t\$this = \$(this);
\t\tajax_url = \$(this).data('ajax_url');
\t\tconsole.log(ajax_url);
\t\t\$this.select2({
\t\t\ttags: tc_tags,
\t\t\tplaceholder: "Tags",
\t\t\tminimumInputLength: 1,
\t\t\tajax: {
\t\t\t\turl: ajax_url,
\t\t\t\tdataType: 'json',
\t\t\t\tquietMillis: 100,
\t\t\t\tdata: function (term, page) {
\t\t\t\t\treturn { q: term };
\t\t\t\t},
\t\t\t\tresults: function (data, page) {
\t\t\t\t\tvar results = {};
\t\t\t\t\tfor(var z in data.data) {
\t\t\t\t\t\tresults[parseInt(z)] = {id: parseInt(z), text: data.data[z]};
\t\t\t\t\t}
\t\t\t\t\treturn {results: results, more: false};
\t\t\t\t},
\t\t\t\tformatSelection: function(item) {
\t\t\t\t\treturn item.text;
\t\t\t\t},
\t\t\t\tformatResult: function(item) {
\t\t\t\t\treturn item.text;
\t\t\t\t}
\t\t\t}
\t\t});

\t});
});
</script>
TAGS_PRE_OUT;
        }
        return $this->controls_js($out);
    }
Example #3
0
	/**
	 * Return the HTML/script required for this control.  Do it only once.
	 * @return string The HTML/javascript required for this control.
	 */
	public function pre_out()
	{
		$out = '';
		if ( !FormControlTextMulti::$outpre ) {
			FormControlTextMulti::$outpre = true;
			$out .= '
				<script type="text/javascript">
				controls.textmulti = {
					add: function(e, field){
						$(e).before("<label><input type=\"text\" name=\"" + field + "[]\"> <a href=\"#\" onclick=\"return controls.textmulti.remove(this);\">[' . _t( 'remove' ) . ']</a></label>");
						return false;
					},
					remove: function(e){
						if (confirm("' . _t( 'Remove this item?' ) . '")) {
							$(e).parent().prev().remove();
							$(e).parent().remove();
						}
						return false;
					}
				}
				</script>
			';
		}
		return $out;
	}
Example #4
0
    /**
     * Return the HTML/script required for this control.  Do it only once.
     * @return string The HTML/javascript required for this control.
     */
    public function pre_out()
    {
        $out = '';
        if (!FormControlTextMulti::$outpre) {
            FormControlTextMulti::$outpre = true;
            $out .= '
				<script type="text/javascript">
				controls.textmulti = {
					add: function(e, field){
						$(e).before(" <span class=\\"textmulti_item\\"><input type=\\"text\\" name=\\"" + field + "[]\\"> <a href=\\"#\\" onclick=\\"return controls.textmulti.remove(this);\\" title=\\"' . _t('Remove item') . '\\" class=\\"textmulti_remove opa50\\">[' . _t('remove') . ']</a></span>");
						return false;
					},
					remove: function(e){
						if (confirm("' . _t('Remove this item?') . '")) {
							if ( $(e).parent().parent().find("input").length == 1) {
								field = $(e).prev().attr("name");
								$(e).parent().prev().before("<input type=\\"hidden\\" name=\\"" + field + "\\" value=\\"\\">");
							}
							$(e).parent().prev("input").remove();
							$(e).parent().remove();
						}
						return false;
					}
				}
				</script>
			';
        }
        return $out;
    }