JavaScript在Maximo中强制执行OnChange [英] JavaScript force an OnChange in Maximo

查看:98
本文介绍了JavaScript在Maximo中强制执行OnChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为Maximo开发一个书签,这是一个Java EE应用程序,我需要填充一些输入框。

I'm currently working on a Bookmarklet for Maximo, which is a Java EE application, and I need to populate a few input boxes.

通常在使用时将数据输入框中,他们单击一个弹出按钮,然后他们搜索要添加到脚本中的值。或者,他们可以键入名称并按Tab / Enter,然后将其转换为大写字母,并在后台执行一些操作(不确定其确切功能)。

Generally when a use inputs data into the box they click a button that gives them a popup and they search for the value to be added to the script. Or they can type the name and hit tab/enter and it turns it to capital letters and does a few things in the background (not sure what it does exactly).

我当前使用

Javascript: $('mx1354').value = "KHBRARR"; $('mx1354').ov= "KHBRARR";

但是它不能像我需要的那样工作。它将输入框设置为所需的值,但是它不运行后台功能,因此当我按下保存按钮时,它不会将其识别为任何更改并丢弃了我在框中输入的内容。

But it does not work like I need it to. It set's the input box to the value needed, but it doesn't run the background functions so when I hit the save button it doesn't recognize it as any changes and discards what I put into the box.

如何模拟已按下的选项卡/输入按钮?

How could I simulate a tab/enter button has been pressed?

到目前为止,我尝试将onchange,focus /模糊并单击函数(不确定我是否正确调用了函数)。

So far I've tried to call the onchange, focus/blur, and click functions (Not 100% sure if I called them correctly).

dojo库是应用程序的一部分,所以我不确定是否可以如果功能或jQuery会引起冲突,请使用它。

The dojo library is part of the application, so I'm not sure if I can use one if it's feature or if jQuery would cause a conflict.

PS这需要在IE中运行。

P.S. This needs to run in IE.

OnChange函数:

The OnChange Function:

function tb_(event)
{
    event = (event) ? event : ((window.event) ? window.event : "");
    if(DESIGNMODE)
        return;
    var ro = this.readOnly;
    var exc=(this.getAttribute("exc")=="1");
    switch(event.type)
    {
        case "mousedown":
            if(getFocusId()==this.id)
                this.setAttribute("stoptcclick","true");
            break;
        case "mouseup":
            if (isIE() && !hasFocus(this)) 
            {
                this.focus();
            }
            if (isBidiEnabled) 
            {
                adjustCaret(event, this); // bidi-hcg-AS
            }
            break;
        case "blur":
            input_onblur(event,this);
            if (isBidiEnabled)                                      // bidi-hcg-SC
                input_bidi_onblur(event, this);
            break;
        case "change":
            if(!ro)
                input_changed(event,this);
            break;
        case "click":
            if(overError(event,this))
                showFieldError(event,this,true);
            var liclick=this.getAttribute("liclick");
            var li=this.getAttribute("li");
            if(li!="" && liclick=="1")
            {
                frontEndEvent(getElement(li),'click');
            }

            if(this.getAttribute("stoptcclick")=="true")
            {
                event.cancelBubble=true;
            }
            this.setAttribute("stoptcclick","false");
            break;
        case "focus":
            input_onfocus(event,this);
            if (isBidiEnabled)                      // bidi-hcg-SC
                input_bidi_onfocus(event, this);
            this.select();
            break;
        case "keydown":
            this.setAttribute("keydown","true");
            if(!ro)
            {
                if(isBidiEnabled)
                    processBackspaceDelete(event,this); // bidi-hcg-AS
                if(hasKeyCode(event, 'KEYCODE_DELETE') || hasKeyCode(event, 'KEYCODE_BACKSPACE'))
                {
                    getHiddenForm().elements.namedItem("changedcomponentvalue").value = this.value;                     
                }
                if((hasKeyCode(event, 'KEYCODE_TAB') || hasKeyCode(event, 'KEYCODE_ESC')))
                {
                    var taMatch = dojo.attr(this, "ta_match");
                    if(taMatch) {
                        if(taMatch.toLowerCase().indexOf(this.value.toLowerCase()) == 0) 
                        {
                            console.log("tamatch="+taMatch);
                            this.value = taMatch;
                            input_keydown(event, this);
                            dojo.attr(this, {"prekeyvalue" : ""});
                            input_forceChanged(this);
                            inputchanged = false;
                            return; // don't want to do input_keydown again so preKeyValue will work
                        }
                    }
                    if(this.getAttribute("PopupType"))
                    {
                        var popup = dijit.byId(dojohelper.getPopupId(this));
                        if (popup)
                        {
                            dojohelper.closePickerPopup(popup);
                            if(hasKeyCode(event, 'KEYCODE_ESC'))
                            {
                                if (event.preventDefault)
                                {  
                                    event.preventDefault();  
                                }
                                else
                                {  
                                    event.returnValue  = false;  
                                }  

                                return;
                            }
                        }
                    }
                }
                input_keydown(event,this);
                datespin(event,this);
            }
            else if(hasKeyCode(event,'KEYCODE_ENTER') || (hasKeyCode(event,'KEYCODE_DOWN_ARROW') && this.getAttribute("liclick")))
            {
                var lbId = this.getAttribute("li");
                frontEndEvent(getElement(lbId), 'click');
            }
            else if(hasKeyCode(event,KEYCODE_BACKSPACE))
            {
                event.cancelBubble=true;
                event.returnValue=false;
            }
            break;
        case "keypress":
            if(!ro)
            {
                if(event.ctrlKey==false && hasKeyCode(event,'KEYCODE_ENTER'))
                {
                    var db = this.getAttribute("db");
                    if(db!="")
                    {
                        sendClick(db);
                    }
                }
            }
            break;
        case "keyup":
            var keyDown = this.getAttribute("keydown");
            this.setAttribute("keydown","false");
            if(event.ctrlKey && hasKeyCode(event,'KEYCODE_SPACEBAR'))
            {
                if(showFieldError(event,this,true))
                {
                    return;
                }
                else
                {
                    menus.typeAhead(this,0);
                }
            }
            if(!ro)
            {
                if(isBidiEnabled)
                    processBidiKeys(event,this); // bidi-hcg-AS

                numericcheck(event,this);   
                var min = this.getAttribute("min");
                var max = this.getAttribute("max");

                if(min && max && min!="NONE" || max!="NONE")
                {
                    if(min!="NONE" && parseInt(this.value)<parseInt(min))
                    {
                        this.value=min;
                        getHiddenForm().elements.namedItem("changedcomponentvalue").value = this.value;                     
                        this.select();
                        return false;
                    }

                    if(max!="NONE" && parseInt(this.value)>parseInt(max))
                    {
                        this.value=max;
                        getHiddenForm().elements.namedItem("changedcomponentvalue").value = this.value;
                        this.select();
                        return false;
                    }
                }
                var defaultButton = false;
                if(event.ctrlKey==false && hasKeyCode(event,'KEYCODE_ENTER'))
                {
                    var db = this.getAttribute("db");
                    if(db!="")
                    {
                        defaultButton=true;
                    }
                }
                input_changed(event,this);                  
            }
            else
            {
                setFocusId(event,this);
            }
            if(showFieldHelp(event, this))
            {
                return;
            }
            if(keyDown=="true" && hasKeyCode(event, 'KEYCODE_ENTER') && !event.ctrlKey && !event.altKey)
            {
                menus.typeAhead(this,0);
                return;
            }
            if(!hasKeyCode(event, 'KEYCODE_ENTER|KEYCODE_SHIFT|KEYCODE_CTRL|KEYCODE_ESC|KEYCODE_ALT|KEYCODE_TAB|KEYCODE_END|KEYCODE_HOME|KEYCODE_RIGHT_ARROW|KEYCODE_LEFT_ARROW')
                    && !event.ctrlKey && !event.altKey)
            {
                menus.typeAhead(this,0);
            }
            break;
        case "mousemove":
            overError(event,this);
            break;
        case "cut":
        case "paste":
            if(!ro)
            {
                var fldInfo = this.getAttribute("fldInfo");
                if(fldInfo)
                {
                    fldInfo = dojo.fromJson(fldInfo);
                    if(!fldInfo.query || fldInfo.query!=true)
                    {
                        setButtonEnabled(saveButton,true);
                    }
                }
                window.setTimeout("inputchanged=true;input_forceChanged(dojo.byId('"+this.id+"'));", 20);
            }
            break;
    }
}


推荐答案

之后一段时间我发现,为了通过JavaScript更改页面,您需要提交一个隐藏的表单,以便可以在后端进行验证。

After some time I found that in order to make a change to the page via JavaScript you need to submit a hidden form so it can verify on the back-end.

这里是

        cc : function(e,v){
            e.focus(); //Get focus of the element
            e.value = v; //Change the value
            e.onchange(); //Call the onchange event
            e.blur(); //Unfocus the element
            console.log("TITLE === "+e.title);
            if(e.title.indexOf(v) != -1) {
                return true; //The value partially matches the requested value. No need to update
            } else {
                //Generate an hidden form and submit it to update the page with the new value
                var hiddenForm = getHiddenForm();
                var inputs = hiddenForm.elements;
                inputs.namedItem("changedcomponentid").value = e.id;
                inputs.namedItem("changedcomponentvalue").value = v;
                inputs.namedItem("event").value = "X"; //Send a Dummy Event so the script see's its invalid and sets the right Event
                submitHidden();
            }
            //Value isn't set to the required value so pass false
            return false;
        }

这篇关于JavaScript在Maximo中强制执行OnChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆