options instanceof \Closure) { $this->options( $this->options->call($this->values(), $this->value(), $this) ); } $this->addCascadeScript(); $radio = WidgetRadio::make($this->getElementName(), $this->options, $this->style); if ($this->attributes['disabled'] ?? false) { $radio->disable(); } $radio ->inline($this->inline) ->check($this->value()) ->class($this->getElementClassString()) ->size($this->size); $this->addVariables([ 'radio' => $radio, ]); return parent::render(); } /** * Add cascade scripts to contents. * * @return string */ protected function getCascadeScript() { if (empty($this->conditions)) { return; } $cascadeGroups = collect($this->conditions)->map(function ($condition) { return [ 'class' => $this->getCascadeClass($condition['value'], $condition['operator']), 'operator' => $condition['operator'], 'value' => $condition['value'], ]; })->toJson(); return <<': function(a, b) { return a > b; }, '<': function(a, b) { return a < b; }, '>=': function(a, b) { return a >= b; }, '<=': function(a, b) { return a <= b; }, '!=': function(a, b) { return ! operator_table['='](a, b); }, 'in': function(a, b) { return Dcat.helpers.inObject(a, String(b), true); }, 'notIn': function(a, b) { return ! Dcat.helpers.inObject(a, String(b), true); }, 'has': function(a, b) { return Dcat.helpers.inObject(b, String(b), true); }, }; var cascade_groups = {$cascadeGroups}, event = '{$this->cascadeEvent}'; \$this.on(event, function (e) { var checked = $(e.target).parent().parent().find(':checked').val(); cascade_groups.forEach(function (event) { var group = $(e.target).closest('.form-group.form-field').next('div.cascade-group.'+event.class); if (compare(checked, event.value, event.operator)) { group.removeClass('d-none'); } else { group.addClass('d-none'); } }); }).trigger(event); })(); JS; } }