Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-15604

checkUrl and codemirror-mode do not mix

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      If you put <f:textarea codemirror-mode="clike"/> in a Jelly page, and there is a doCheckWhatever method for the field in the corresponding Descriptor, the validation will not work—it will only validate the contents of the text area when the page was loaded, regardless of subsequent edits.

      The cause seems to be that e.value (used from controlValuetoValueqstargetUrlregisterValidatorTEXTAREA.validated) does not update dynamically when CodeMirror is used, unless and until e.codemirrorObject.save() is called.

        Attachments

          Issue Links

            Activity

            Hide
            jglick Jesse Glick added a comment -

            Workaround:

            <script>
              function cmChange(editor, change) {
                editor.save();
                $$('.validated').forEach(function (e) {e.onchange()})
              }
            </script>
            <f:textarea codemirror-mode="clike" codemirror-config="'onChange': cmChange"/>
            

            (getTextArea is apparently undefined in this version of codemirror.js, hence the loop over all validated elements.)

            Show
            jglick Jesse Glick added a comment - Workaround: <script> function cmChange(editor, change) { editor.save(); $$( '.validated' ).forEach(function (e) {e.onchange()}) } </script> <f:textarea codemirror-mode= "clike" codemirror-config= " 'onChange' : cmChange" /> ( getTextArea is apparently undefined in this version of codemirror.js , hence the loop over all validated elements.)
            Hide
            jglick Jesse Glick added a comment -

            Actually need to use <st:adjunct> to define the JavaScript when this is part of a lazy-loaded block.

            Triggering form validation on every keypress slows down the browser and server a bit, so configuring onBlur is preferable. Would be nice to validate a focused textarea but wait for quiescence (of say three seconds) before triggering validation. This seems hard from plugin code, since registerValidator is hardcoded to call sendRequest rather than delayedCheck; would need to build a custom timer of some kind.

            Show
            jglick Jesse Glick added a comment - Actually need to use <st:adjunct> to define the JavaScript when this is part of a lazy-loaded block. Triggering form validation on every keypress slows down the browser and server a bit, so configuring onBlur is preferable. Would be nice to validate a focused textarea but wait for quiescence (of say three seconds) before triggering validation. This seems hard from plugin code, since registerValidator is hardcoded to call sendRequest rather than delayedCheck ; would need to build a custom timer of some kind.
            Hide
            jglick Jesse Glick added a comment -

            Seems to require each rather than forEach to avoid errors.

            For some reason, in 1.509.4 this textarea has more serious problems than form validation: you cannot consistently get focus into it in IE 9, and not at all in Chrome. Disabling CodeMirror suffices to restore functionality.

            Show
            jglick Jesse Glick added a comment - Seems to require each rather than forEach to avoid errors. For some reason, in 1.509.4 this textarea has more serious problems than form validation: you cannot consistently get focus into it in IE 9, and not at all in Chrome. Disabling CodeMirror suffices to restore functionality.
            Hide
            jglick Jesse Glick added a comment -

            Tried to use the attached patch to add shell syntax highlighting to CommandInstaller in trunk. This seems to cause weird issues when reloading the configuration page; existing scripts are invisible until you start editing them, and with a zero-height textarea.

            Show
            jglick Jesse Glick added a comment - Tried to use the attached patch to add shell syntax highlighting to CommandInstaller in trunk. This seems to cause weird issues when reloading the configuration page; existing scripts are invisible until you start editing them, and with a zero-height textarea.
            Show
            jglick Jesse Glick added a comment - Cf.: https://github.com/jenkinsci/script-security-plugin/blob/aa0c8b28290b5d77d160684f2ffc3737a1856e1b/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/groovy/SecureGroovyScript/config.jelly#L29

              People

              • Assignee:
                jglick Jesse Glick
                Reporter:
                jglick Jesse Glick
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: