EPrints Technical Mailing List Archive
Message: #06735
< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First
[EP-tech] Enabling/disabling fields in the workflow using JS
- To: <eprints-tech@ecs.soton.ac.uk>
- Subject: [EP-tech] Enabling/disabling fields in the workflow using JS
- From: Robin Sylvestre <robin.sylvestre@polymtl.ca>
- Date: Tue, 1 Aug 2017 16:51:30 -0400 (EDT)
Hello fellow Eprinters! I’m trying to enable/disable a date field in the workflow based on the value of a radio button (value = True or False), using _javascript_. Is there an easy way to do it? This page contains some clues and I’ve tried adding a render_input option to my field definition: { 'name' => 'diplome_articles', 'type' => 'boolean', 'multiple' => 0, 'volatile' => 0, 'input_style' => 'radio', 'render_input' => sub { my ( $field, $repository, $current_value, $dataset, $staff, $hidden_fields, $object, $basename ) = @_; my $dom = $field->render_input_field_actual( $repository, $current_value, $dataset, $staff, $hidden_fields, $object, $basename ); my $script = $repository->make_javascript(' var buttonOpt = document.getElementById("'.$basename.'"); buttonOpt.addEventListener("click", function(){ alert() }); '); my $superdom = $repository->xml->create_element("div"); $superdom->appendChild($dom); $superdom->appendChild($script); return $superdom; } } …but since both radio buttons (true/false) get the same ID when rendered by EPrints, using “getElementById” returns only the first element, thus only works when the first option is clicked. From the console of my browser, I know I can get the value of the selected option using document.querySelector("[name$='_diplome_articles']:checked").value …but I can’t figure out how to add an event listener for when this value is changing. Actually, the much, much easier way would be to just add _onclick_="function()" to the radio button itself and toggle the date field accordingly. But is it possible to do it without hacking EPrints too much? Thanks for your help!! Robin Sylvestre Technicien en gestion de l’information numérique Services techniques et systèmes informatisés Bibliothèque de l’École Polytechnique de Montréal 514-340-4711 poste 3743 |
- Prev by Date: [EP-tech] doctype views with monograph-type and pres_type
- Next by Date: Re: [EP-tech] Enabling/disabling fields in the workflow using JS
- Previous by thread: [EP-tech] doctype views with monograph-type and pres_type
- Next by thread: Re: [EP-tech] Enabling/disabling fields in the workflow using JS
- Index(es):