Skip to main content
You are viewing help content for pre-release software. This document and the features it describes are subject to change.
All docs
V26.1
  • SmartPasteBase.Completed Event

    Fires when the Smart Paste operation finishes.

    Namespace: DevExpress.AIIntegration.Blazor

    Assembly: DevExpress.AIIntegration.Blazor.Common.v26.1.dll

    Declaration

    [Parameter]
    public EventCallback<SmartPasteCompletedEventArgs> Completed { get; set; }

    Parameters

    Type Description
    SmartPasteCompletedEventArgs

    A Smart Paste operation result.

    Remarks

    Use the Completed event to handle the result of a Smart Paste operation in Blazor components.

    The following code handles the Form Layout Smart Paste extension’s Completed event and displays messages about populated fields or operation errors:

    @using DevExpress.AIIntegration.Blazor
    @using DevExpress.AIIntegration.Blazor.Layout
    @using DevExpress.AIIntegration.Extensions
    
    <DxMemo @bind-Text="SampleText"
            Rows="14"
            ResizeMode="MemoResizeMode.Auto" />
    
    <DxFormLayout @ref="FormLayout"
                  Data="@model"
                  CssClass="w-100 mb-2">
        <Extensions>
            <FormLayoutSmartPaste ItemDescriptions="@fieldDescriptions"
                                  PromptAugmentation="@PromptAugmentation"
                                  Completed="OnSmartPasteCompleted" />
        </Extensions>
        <ChildContent>
            <DxFormLayoutItem Caption="Full Name" ColSpanMd="12"
                              Field="@nameof(BillingFormModel.FullName)">
                <DxTextBox @bind-Text="@model.FullName"
                           NullText="Full Name" />
            </DxFormLayoutItem>
            <DxFormLayoutItem Caption="Amount Due" ColSpanMd="12"
                              Field="@nameof(BillingFormModel.AmountDue)">
                <DxMaskedInput @bind-Value="@model.AmountDue"
                               Mask="@NumericMask.Currency"
                               NullText="$0.00" />
            </DxFormLayoutItem>
            <DxFormLayoutItem Caption="Statement Date" ColSpanMd="12"
                              Field="@nameof(BillingFormModel.StatementDate)">
                <DxDateEdit @bind-Date="@model.StatementDate"
                            NullText="MM/DD/YYYY" />
            </DxFormLayoutItem>
            @*...*@
        </ChildContent>
    </DxFormLayout>
    
    <DxButton Text="Smart Paste"
              IconCssClass="icon-ai-sparkle"
              RenderStyle="ButtonRenderStyle.Primary"
              Click="OnSmartPaste" />
    <DxButton Text="Reset"
              RenderStyle="ButtonRenderStyle.Secondary"
              Click="@OnResetClick" />
    
    <p>Status: @LastResponse?.Status</p>
    <p>Status Message: @StatusMessage</p>
    
    @code {
        DxFormLayout FormLayout { get; set; }
        BillingFormModel model = new();
        string StatusMessage { get; set; };
        SmartPasteResponse LastResponse { get; set; } = null;
    
        readonly Dictionary<string, string> fieldDescriptions = new() {
            { nameof(BillingFormModel.PhoneNumber), "US phone number. 
            Return exactly 10 digits without any formatting characters."}
        };
    
        const string PromptAugmentation =
            "Always override the current field value with the extracted one.";
    
        string SampleText { get; set; } =
            "Hi there,\n" +
            " \n" +
            "Following up on billing for April. The balance should be twelve hundred " +
            "— it was adjusted after our last conversation.\n" +
            "I also moved recently. My new billing address is:\n" +
            "123 Market Street, San Francisco, CA 94103\n" +
            "You can keep using my email: john.smith@dx-email.com.\n" +
            "For phone, please use my mobile number going forward: 415-555-0199 " +
            "(not the office line).\n" +
            "The statement date should be mid-April.\n" +
            "Let me know if you need anything else.\n" +
            " \n" +
            "Best regards,\n" +
            "John Smith";
    
        async Task OnSmartPaste() {
            model.Reset();
            await FormLayout.SmartPasteAsync(SampleText);
        }
    
        void OnResetClick() {
            model.Reset();
        }
    
        void OnSmartPasteCompleted(SmartPasteCompletedEventArgs args) {
            if (args.IsError) {
                StatusMessage = $"Error: {args.ErrorMessage}";
                return;
            }
            LastResponse = args.Response!;
            if (LastResponse is { IsCompleted: true }) {
                StatusMessage = $"Smart Paste completed. {LastResponse.Values.Count} field(s) populated.";
            }
            else {
                StatusMessage = $"AI returned status: {LastResponse?.Status}";
            }
        }
    }
    
    See Also