Home Forums Plugin Support WP User Frontend Pro Help with js

This topic is: not resolved

This topic contains 3 replies, has 2 voices, and was last updated by  Nayem 4 years, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #37718

    Rob
    Member
    Post count: 101

    Hi

    I have created an action hook for a calculated field, which works fine. However I'm struggling to make the field conditional.

    /*-- Land area in WPUF ---*/
    function render_land_area_hook( $form_id, $post_id, $form_settings ) {
        $value1 = '';
        $value2 = '';
        if ( $post_id ) {
            $value1 = get_post_meta( $post_id, 'land_area', true );
        }
        ?>
     <li class="wpuf-el land_area2">  
        <div class="wpuf-label">
            <label>Land Area</label>
        </div>
        <script type="text/javascript">
    	  function calc(){
    	      //grab the values
    	      area_acres = document.getElementById('area_acres').value;
    	      document.getElementById('area_m2').value = parseFloat(4046.86 * area_acres).toFixed(0);
    	  }
    	  function calc_rev(){
    	      area_m2 = document.getElementById('area_m2').value;
    	      document.getElementById('area_acres').value = parseFloat(area_m2 / 4046.86).toFixed(2);
    	  }
        </script>
    
        <div class="wpuf-fields">
            <input name="land_area_m2" id="area_m2" type="text" onblur="calc_rev()"> m<sup>2</sup> OR  <input name="land_area_acres" id="area_acres" type="text" onblur="calc()"> acres
        </div>
    
    <script type="text/javascript">
                wpuf_conditional_items.push({"condition_status":"yes","cond_field":["steps"],"cond_operator":["="],"cond_option":["1 Basics"],"cond_logic":"any","type":"text","name":"land_area2","form_id":"2422"});
    </script>
    
        <?php
    }
    add_action( 'land_area_hook', 'render_land_area_hook', 10, 3 );
    // update
    function update_land_area( $post_id ) {
        if ( isset( $_POST['land_area_m2'] ) ) {
            update_post_meta( $post_id, 'land_area', $_POST['land_area_m2'] );
        }
    }
      
    add_action( 'wpuf_add_post_after_insert', 'update_land_area' );
    add_action( 'wpuf_edit_post_after_update', 'update_land_area' );

    What am I doing wrong?

    Many thanks

    #37876

    Nayem
    Moderator
    Post count: 6480

    Hello Rob,

    I have to discuss with our developer team. I will be back to you after finishing the discussion.

    Thank you ๐Ÿ™‚

    #40135

    Rob
    Member
    Post count: 101

    Any progress with this enquiry?

    #40228

    Nayem
    Moderator
    Post count: 6480

    Hello Rob,

    Please open Wp user fronted/class/render-form.php in this file you will get this function-function conditional_logic( $form_field, $form_id ). You can follow those step which have done here.

    Thank you ๐Ÿ™‚

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Help with js’ is closed to new replies.