KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Auto Reset Input #3198

Closed afieq opened this topic on on Nov 25, 2023 - 7 comments

afieq commented on Nov 25, 2023

Hi,

I'm facing a problem where i have 2 input on my dashboard consist Year input and Quarter Month input dropdown. Currently i picked value on Quarter Month input after the Year input, and then i picked a new value on Year input but the value on Quarter input still remain the same.

How can i reset the Quarter Month input to default value when i pick a new value on the Year input?

Thanks in advance.

Regards, Afieq

afieq commented on Nov 27, 2023

Hi,

Any help can i get on this issue? Anyone?

Regards, Afieq

KoolReport commented on Nov 27, 2023

In the Year input dropdown, you use the actionSubmit() to reset the quarter and month input. Something like this:

protected function actionSubmit($request, $response)
{
    $this->sibling("quarter")->update();
    $this->sibling("month")->update();
}
afieq commented on Nov 30, 2023

Hi KoolReport,

I have tried your suggestion but it does not work as you said. I already added the actionSubmit button but the value of the quarter input still remain the same. It does not reset the value as i target. Any other solution for this problem?

Regards, Afieq

KoolReport commented on Nov 30, 2023

Can you show me your code?

afieq commented on Nov 30, 2023

Hi KoolReport,

Below is my code for Year input for your reference.

<?php

namespace home;

use \koolreport\dashboard\inputs\Select;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Number;
use \MyTable;

class YearRange extends Select
{
    protected function onCreated()
    {
        $this->defaultOption(["--"=>null]);
    }

    protected function dataSource()
    {
        return MyTable::rawSQL("
                select year_value as Year
                from year_table
            ");
    }

    protected function actionChange($request, $response)
    {
        $this->sibling("MyReport")->update();
    }

    protected function actionSubmit($request, $response)
    {
        $this->sibling("QuarterRange")->update();
    }

    protected function fields()
    {
        return [
            Text::create("Year"),
        ];
    }
}

Regards, Afieq

KoolReport commented on Nov 30, 2023

I see, I thought you using Dropdown widget, not the Select. So in this case, you use the actionChange()

protected function actionChange($request, $response)
{
    $this->sibling("quarter")->value(1)->update();
    $this->sibling("month")->value(1)->update();
}

On year change, you simply set the value for quarter and month then update them.

afieq commented on Nov 30, 2023

Hi KoolReport,

I have added and tried the code you suggest and now it works like a charm. Thank you for your help on solving my issue.

Regards, Afieq

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

Inputs