Skip to content

Instantly share code, notes, and snippets.

@richardW8k
Last active April 28, 2016 17:29
Show Gist options
  • Save richardW8k/866435d6db255ab2acb6 to your computer and use it in GitHub Desktop.
Save richardW8k/866435d6db255ab2acb6 to your computer and use it in GitHub Desktop.

Revisions

  1. richardW8k revised this gist Apr 28, 2016. No changes.
  2. richardW8k revised this gist Jul 15, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RW_GF_Rating_Field_Logic.php
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ public function __construct() {
    }

    function init() {
    if ( ! property_exists( 'GFForms', 'version' ) || ! version_compare( GFForms::$version, '1.9', '>=' ) ) {
    if ( ! property_exists( 'GFForms', 'version' ) || ! version_compare( GFForms::$version, '1.9.10', '>=' ) ) {
    return;
    }

  3. richardW8k created this gist Jul 15, 2015.
    42 changes: 42 additions & 0 deletions RW_GF_Rating_Field_Logic.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    class RW_GF_Rating_Field_Logic {

    public function __construct() {
    add_action( 'init', array( $this, 'init' ) );
    }

    function init() {
    if ( ! property_exists( 'GFForms', 'version' ) || ! version_compare( GFForms::$version, '1.9', '>=' ) ) {
    return;
    }

    add_filter( 'gform_field_content', array( $this, 'maybe_add_logic_event' ), 10, 2 );
    add_filter( 'gform_admin_pre_render', array( $this, 'enable_rating_in_conditional_logic' ) );
    }

    function maybe_add_logic_event( $content, $field ) {
    if ( $field->get_input_type() != 'rating' ) {
    return $content;
    }
    $logic_event = $field->get_conditional_logic_event( 'change' );

    return ! empty( $logic_event ) ? str_replace( "radio'", "radio' {$logic_event}", $content ) : $content;

    }

    function enable_rating_in_conditional_logic( $form ) {
    if ( GFCommon::is_entry_detail() ) {
    return $form;
    }

    echo "<script type='text/javascript'>" .
    " gform.addFilter('gform_is_conditional_logic_field', function (isConditionalLogicField, field) {" .
    " return field.inputType == 'rating' ? true : isConditionalLogicField;" .
    ' });' .
    '</script>';

    return $form;
    }

    }

    new RW_GF_Rating_Field_Logic();