using CustomEditor prevents [Preview] from becoming enabled

1 Answer 12 Views
Report Parameters Report Viewer - MVC
David
Top achievements
Rank 1
Iron
David asked on 02 Dec 2025, 07:01 PM

This is my declaration in the .cshtml file:

        @(Html.TelerikReporting().ReportViewer()
                .Id("reportViewer1")
                .ServiceUrl(Url.Content("~/api/reports"))
                .ReportSource(new TypeReportSource() { TypeName = "ReportLibrary." + Model.FormReportsModel.ReportID.ToString() + ", ReportLibrary" })
                .ViewMode(ViewMode.Interactive)
                .ScaleMode(ScaleMode.Specific)
                .Scale(1.0)
                .PersistSession(false)
                .PrintMode(PrintMode.AutoSelect)
                .EnableAccessibility(true)
                .ClientEvents(events => events.RenderingBegin("onRenderingBegin"))
                .ClientEvents(events => events.RenderingEnd("onRenderingEnd"))
                .ParameterEditors(
                    editors => editors
                        .CustomEditors(new CustomParameterEditor
                        {
                            MatchFunction        = "customMatch",
                            CreateEditorFunction = "createCustomEditor"
                        })
                )
        )


It's been running fine for years without the "ParameterEditors" bit.  I added that not because I want to really edit a parameter, only because I realized I could change the initial hint:

            function customMatch(p1) {
                if (p1.name === "AccountID")       p1.Error = "Please choose one";
                if (p1.name === "FiscalManyYears") p1.Error = "Please choose at least two";
                return false;
            }

            function createCustomEditor(placeholder, options) {
                // This is not needed, because the previous function never returns TRUE.
            }

which works great on the new report . . . but suddenly all of the other reports are failing, because the [Preview] button never enables, no matter what selections are clicked for the parameters.  If I remove the ".ParameterEditors()" clause, the [Preview] button reverts to behaving as expected.

I would be happy if someone could point out a mistake I'm making.

1 Answer, 1 is accepted

Sort by
0
Accepted
David
Top achievements
Rank 1
Iron
answered on 03 Dec 2025, 04:12 PM | edited on 03 Dec 2025, 04:42 PM

Figured it out.  This is the corrected code:


function customMatch(p1) {
    // I thought this function would be invoked only once, but it is actually called in two different situations:
    //     #1  during the population of the parameter sidebar, by the Telerik function onReloadParameters()
    //     #2  each time any parameter value is clicked, by the Telerik function onSelectionChanged()
    // During the latter, if the user's choice is valid, the member "Error" does not exist, so any attempt
    // to assign a value to it or even examine it is an exception, in which case FALSE is _not_ returned,
    // so the parameter's value is considered invalid, therefore it refuses to enable the [Preview] button.
    //
    // I realize I could be overwriting a legitimate error message, but I'm fine with that.
    // It's worth it to provide a more meaningful initial hint.
    if (p1 !== null) {
        if (typeof p1.Error !== typeof undefined) {
            if (p1.name === "AccountID")       p1.Error = "Please choose one";
            if (p1.name === "FiscalManyYears") p1.Error = "Please choose at least two";
        }
    }
    return false;
}

Tags
Report Parameters Report Viewer - MVC
Asked by
David
Top achievements
Rank 1
Iron
Answers by
David
Top achievements
Rank 1
Iron
Share this question
or