I have a problem using the Material UI's Autocomplete with Reagent (ClojureScript). The element renders fine, but when I try to click on it, I get the following exceptions:
Uncaught TypeError: Cannot read property 'focus' of null
at handleClick (useAutocomplete.js:938)
at HTMLUnknownElement.callCallback (react-dom.development.js:189)
at Object.invokeGuardedCallbackImpl (react-dom.development.js:238)
at invokeGuardedCallback (react-dom.development.js:293)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:307)
at executeDispatch (react-dom.development.js:390)
at executeDispatchesAndReleaseTopLevel (react-dom.development.js:412)
at forEachAccumulated (react-dom.development.js:3260)
at runEventsInBatch (react-dom.development.js:3305)
at handleTopLevel (react-dom.development.js:3515)
useAutocomplete.js:322 Uncaught TypeError: Cannot read property 'removeAttribute' of null
at eval (useAutocomplete.js:322)
at eval (useEventCallback.js:26)
at eval (useAutocomplete.js:433)
at eval (useEventCallback.js:26)
at eval (useAutocomplete.js:463)
at eval (useAutocomplete.js:528)
at commitHookEffectListMount (react-dom.development.js:19765)
at commitPassiveHookEffects (react-dom.development.js:19803)
at HTMLUnknownElement.callCallback (react-dom.development.js:189)
at Object.invokeGuardedCallbackImpl (react-dom.development.js:238)
Breaking in JS debugger, I see that inputRef.current is null (which is what focus and removeAttribute are called on. (Oddly enough, the only place where inputRef is set in the file is by calling useRef(null), which is what results in inputRef.current being null.)
In my code, I define the Autocomplete field as follows:
(ns my-product-redacted.views.atoms
(:require [reagent.core :as r]
["#material-ui/lab/Autocomplete" :default Autocomplete]
;; other requires
))
(def autocomplete-field (r/adapt-react-class Autocomplete))
Then, in a React component, it is used as follows:
[a/autocomplete-field {:render-input (fn [js-params]
(let [clj-params (js->clj js-params)
params {:label label
:width width
:select select?
:Input-label-props {:shrink true}
:Select-props {:native true}}
all-params (into clj-params params)]
(js/console.log (clj->js all-params))
(r/as-element [a/text-field all-params])))
:options (when select? (cons {:value "" :label ""} options))
:get-option-label (fn [option] (or (get (js->clj option) "label") ""))
:default-value (when (not select?) value-override)
:value (when select? value)
:disabled disabled?
:on-focus #(re-frame/dispatch [::forms/on-focus path])
:on-blur #(re-frame/dispatch [::forms/on-blur path])
:on-change #(re-frame/dispatch (conj on-change (-> % .-target .-value)))})]
(Here, a/text-field is also defined in the same namespace as a/autocomplete-field and in a similar way.)
The JS console log (from the (js/console.log (clj->js params)) call) shows that inputProps.ref.current is set to null. However, InputProps.ref is not null. Even so, I tried to manually associate the same function as is passed with InputProps.ref to inputProps.ref.current, but that made no difference.
I have also tried the workaround suggested in https://github.com/mui-org/material-ui/issues/21245 (although that issue is with the Gestalt library, not with Reagent, it suggests that there may be a problem with ref forwarding). But wrapping the text-field into a div with the ref taken from InputProps.ref also made no difference.
Any suggestions?
Calling js->clj on the render-input js params breaks them.
I put a quick demo of the material UI autocomplete component in my demo repository here.
But it's mainly taken from the official reagent docs/examples here:
(defn autocomplete-example []
[:> mui/Grid
{:item true}
[:> Autocomplete {:options ["foo" "bar" "foobar"]
:style {:width 300}
;; Note that the function parameter is a JS Object!
;; Autocomplete expects the renderInput value to be function
;; returning React elements, not a component!
;; So reactify-component won't work here.
:render-input (fn [^js params]
;; Don't call js->clj because that would recursively
;; convert all JS objects (e.g. React ref objects)
;; to Cljs maps, which breaks them, even when converted back to JS.
;; Best thing is to use r/create-element and
;; pass the JS params to it.
;; If necessary, use JS interop to modify params.
(set! (.-variant params) "outlined")
(set! (.-label params) "Autocomplete")
(r/create-element mui/TextField params))}]])
I try to disable popup blocking in Robot Framework for Firefox in different ways: by setting preference dom.disable_beforeunload=False, setting capabilities and profile. It does not work. Pop up confirmation windows are not shown. See Open Firefox browser keyword:
*** Keywords ***
Open Firefox browser
${options}= Evaluate sys.modules['selenium.webdriver'].FirefoxOptions() sys
Call Method ${options} set_preference dom.disable_beforeunload False
Call Method ${options} set_capability unhandledPromptBehavior ignore
Call Method ${options} set_capability unexpectedAlertBehaviour ignore
${profile}= Evaluate sys.modules['selenium.webdriver'].FirefoxProfile() sys
Call Method ${profile} set_preference dom.disable_beforeunload False
${desired_capabilities}= Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.FIREFOX sys
Set To Dictionary ${desired_capabilities} unhandledPromptBehavior ignore
Set To Dictionary ${desired_capabilities} unexpectedAlertBehaviour ignore
Open Browser ${LOGIN_URL} Firefox options=${options} ff_profile_dir=${profile} desired_capabilities=${desired_capabilities}
For Chrome there is no such a problem. Everything works by adding the argument --disable-popup-blocking.
Open Chrome browser
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys
Call Method ${options} add_argument --disable-popup-blocking
Call Method ${options} add_argument --ignore-certificate-errors
Open Browser ${LOGIN_URL} Chrome options=${options}
I am new to auto hot key scripting can any one help me out how do I click on the hyper link text using Auto hot key script / Batch File.
My requirement is :
Right click on the Desktop --> In Screen Resolution Screen --> Advanced Settings. So I want to click on the Advanced Settings link automatically when I run the auto hot key script . Please do find the below Image:
Please Find My Below Code Using Mouse Cursor .. I Had Achieved through Mouse cursor but I don't think so that this is going to be the final solution.
#SingleInstance force
#persistent
Run,Desk.cpl
SetTimer, Check, 100
return
Check:
IfWinActive, ahk_class CabinetWClass
MouseMove, 658, 368
Click
Sleep, 1000
IfWinActive, ahk_class #32770
MouseMove, 212, 64
Click
Sleep, 1000
IfWinActive, ahk_class #32770
MouseMove, 93, 360
Click
Sleep, 1000
IfWinActive, ahk_class #32770
MouseMove, 81, 392
Click
Sleep, 1000
IfWinActive, ahk_class #32770
ControlClick,&Apply,ahk_class #32770
IfWinActive, ahk_class #32770
ControlClick,OK,ahk_class #32770
IfWinActive, ahk_class #32770
ControlClick,&Yes,ahk_class #32770
IfWinActive, ahk_class CabinetWClass
ControlClick,OK,ahk_class CabinetWClass
IfWinNotExist, ahk_class CabinetWClass {
ExitApp
return
}
This AutoHotkey script invokes the hyperlink directly by using Microsoft Active Accessibility (MSAA).
This script opens the windows as required and sets True Color (32 bit) (tested on Windows 7) by using direct methods rather than by sending clicks to coordinates.
Note: the script requires Acc.ahk.
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
Note: in my case the window title for the popup window was '(Multiple Monitors) and Intel(R) HD Graphics Family Properties',
you may need to change this in the script if your window has a different title.
q:: ;set True Color (32 bit) (tested on Windows 7)
windir := A_WinDir
vTarget = %windir%\system32\control.exe desk.cpl,Settings,#Settings
Run, %vTarget%
WinWaitActive, Screen Resolution ahk_class CabinetWClass
ControlGet, hCtl, Hwnd, , DirectUIHWND4, Screen Resolution ahk_class CabinetWClass
oAcc := Acc_Get("Object", "4.1.1.14", 0, "ahk_id " hCtl)
if (oAcc.accName(0) = "Advanced settings")
oAcc.accDoDefaultAction(0)
vWinCriteria = (Multiple Monitors) and Intel(R) HD Graphics Family Properties ahk_class #32770
WinWaitActive, %vWinCriteria%
WinGet, hWnd, ID, %vWinCriteria%
SendMessage, 0x1330, 1, , SysTabControl321, ahk_id %hWnd% ;TCM_SETCURFOCUS := 0x1330
Control, ChooseString, True Color (32 bit), ComboBox2, ahk_id %hWnd%
ControlGetText, vText, Button5, ahk_id %hWnd%
if (vText = "OK")
ControlClick, Button5, ahk_id %hWnd%
MsgBox % "done"
Return
Useful links:
Executing Control Panel Items (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/cc144191(v=vs.85).aspx
Canonical Names of Control Panel Items (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ee330741(v=vs.85).aspx
[found by searching for: AutoHotkey "True Color (32 bit)"]
Dual Display Toggle (Display Properties Replacement) - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/22372-dual-display-toggle-display-properties-replacement/
[EDIT:]
[found by searching for: AutoHotkey DEVMODE]
[SOLVED] How To Change Resolution of Both Monitors At Once? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?t=19467
The link has a custom function, ChangeDisplaySettings,
which may do what you want, (but I would urge you
to check the code thoroughly before executing it):
ChangeDisplaySettings(False, 32)
Note: it may only work correctly with the 32-bit version of AutoHotkey
(which can be run on 64-bit Windows).
[EDIT 2:]
I wrote some code to query rather than set the value:
w:: ;get display data
vSizeTCHAR := A_IsUnicode ? 64 : 32
vSizeDEVMODE := 92 + (vSizeTCHAR * 2)
vOffsetBitsPerPel := 40 + (vSizeTCHAR * 2) ;dmBitsPerPel
;ENUM_CURRENT_SETTINGS := -1
;ENUM_REGISTRY_SETTINGS := -2
VarSetCapacity(DEVMODE, vSizeDEVMODE, 0)
vRet := DllCall("EnumDisplaySettings", Ptr,0, UInt,-1, Ptr,&DEVMODE)
MsgBox % NumGet(DEVMODE, vOffsetBitsPerPel, "UInt")
Return
Best of luck!
In Om, is there a way to add a class to an element based on some value in the main app atom?
Take the following element, for example:
(defn some-component [app owner]
(reify
om/IRender
(render
[_]
(html
[:div {:class (when (:some-key app) "awesomeclass")} "Some text!"]))))
If I somehow toggle the value of :some-key between true and false, the class doesn't get added or removed. The value of :some-key on page load determines whether or not the class gets added.
I am using this idea to conditionally show/hide (using Twitter Bootstrap's hide class) menu options based on the value of the :access key in my app state:
[:ul.dropdown-menu {:role "menu"}
[:li {:class (when (:access app) "hide")} [:a.pointer {:on-click #(om/update! app :view :login)} "Login"]]
[:li {:class (when (:access app) "hide")} [:a.pointer {:on-click #(om/update! app :view :register)} "Register"]]
[:li {:class (when-not (:access app) "hide")} [:a.pointer {:on-click #(om/update! app :view :dashboard)} "Dashboard"]]
[:li {:class (when-not (:access app) "hide")} [:a.pointer {:on-click #(om/update! app :view :settings)} "Settings"]]
[:li [:a.pointer {:on-click #(om/update! app :view :about)} "About"]]]
This code works as expected. When I click on "Click Me!", while looking at the Elements in Developer Tools (Chrome), I see the class toggling between "awesomeclass" and disappearing:
(defonce app-state (atom {:some-key true}))
(defn main []
(om/root
(fn [app owner]
(reify
om/IRender
(render [_]
(html
[:div {:class (when (:some-key app) "awesomeclass")}
"Some text!"
[:a {:on-click #(om/transact! app :some-key not)}
"Click Me!"]]))))
app-state
{:target (. js/document (getElementById "app"))}))
As rojoca pointed out, the problem might be in the way you update app-state, consider using om/transact! and om/update!. If you keep having problems, post the code that updates the state.
Note: I'm running this in Chestnut.
You should use the keyword :className instead of :class.
I want to add a checkbox to the finish page of installer. I have already two checkboxes on finishpage, one for showing readme file and other for opening another link. Now I want to add third checkbox for opening home page of my application.
I am following the steps given in this question as this is the exact thing which I want to achieve
Customizing an exsisting NSIS MUI2 page
but the third checkbox is not appearing on finishpage. I am using MUI2.
Here is my code
!include "MUI2.nsh"
var newCheckBox
Function showNewCheckbox
${NSD_CreateCheckbox} 50u 60u 100% 10u "&Launch Google"
Pop $newCheckBox
FunctionEnd
Function launchNewLink
${NSD_GetState} $newCheckBox $0
${If} $0 <> 0
ExecShell "open" "http://google.com"
${EndIf}
FunctionEnd
Function LaunchLink
ExecShell "open" "http://yahoo.com"
FunctionEnd
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_NOTCHECKED
!define MUI_FINISHPAGE_RUN_TEXT "Open yahoo"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_SHOWREADME "${README_FILE}"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW showNewCheckbox
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE launchNewLink
!insertmacro MUI_PAGE_FINISH
Am I missing something??
If $newCheckBox is a number != 0 it means the control was created, maybe its just behind the image on the left? Try 120u 175u as the first two numbers.
If you don't need a checkbox you can just use the link:
!define MUI_FINISHPAGE_LINK "My website"
!define MUI_FINISHPAGE_LINK_LOCATION "http://example.com"
!insertmacro MUI_PAGE_FINISH