Action.Submit not work in angular 6
Hello Developers,
I'm use adaptive card in angular 6 so action submit not working. Can you help any one to submit action and how to do work with and filtered data from AzureChatbot.
I used the following code but not working:
constructor() {
this.adaptiveCard = new AdaptiveCards.AdaptiveCard();
}
ngOnInit() {
// this.adaptiveCard = new AdaptiveCards.AdaptiveCard();
// this.adaptiveCard.hostConfig = new AdaptiveCards.HostConfig({
// fontFamily: "Segoe UI, Helvetica Neue, sans-serif"
// // More host config options
// });
// Set the adaptive card's event handlers. onExecuteAction is invoked
// whenever an action is clicked in the card
this.adaptiveCard.OnSubmit = function(action) { alert("Ow!"); }
// For markdown support you need a third-party library
// E.g., to use markdown-it, include in your HTML page:
// <script type="text/javascript" src="https://unpkg.com/markdown-it/dist/markdown-it.js"></script>
// And add this code to replace the default markdown handler:
// AdaptiveCards.processMarkdown = function(text) { return markdownit().render(text); }
// Parse the card payload
this.adaptiveCard.parse(this.cardsValue);
// Render the card to an HTML element:
this.renderCards = this.adaptiveCard.render();
this.cards.nativeElement.innerHTML=this.renderCards.innerHTML;
// this.innerHTMLVal=this.renderCards;
// this.item = this.renderCards;;
console.log('carddss');
console.log(this.renderCards)
console.log(this.cardsValue)
}
.....................................
{
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Month"
},
{
"type": "Input.ChoiceSet",
"id": "month",
"value": "1",
"style": "compact",
"isMultiSelect": false,
"choices": [
{
"title": "Jan",
"value": "Jan"
},
{
"title": "Feb",
"value": "Feb"
},
{
"title": "Mar",
"value": "Mar"
},
{
"title": "Apr",
"value": "Apr"
},
{
"title": "May",
"value": "May"
},
{
"title": "Jun",
"value": "Jun"
},
{
"title": "Jul",
"value": "Jul"
},
{
"title": "Aug",
"value": "Aug"
},
{
"title": "Sep",
"value": "Sep"
},
{
"title": "Oct",
"value": "Oct"
},
{
"title": "Nov",
"value": "Nov"
},
{
"title": "Dec",
"value": "Dec"
}
],
"placeholder": "select"
}
],
"actions": [
{
"type": "Action.Submit",
"data": {
"type": "submit"
},
"title": "Submit"
}
]
}
this json strigy data use to create adaptive card...card created successfully but submit action not working.
hi @lokeshbansal1993, I think at some point you renamed onExecuteAction to OnSubmit
Try changing:
adaptiveCard.OnSubmit = function(action) { alert("Ow!"); }
to
adaptiveCard.onExecuteAction = function(action) { alert("Ow!"); }
hi @lokeshbansal1993, I think at some point you renamed
onExecuteActiontoOnSubmitTry changing:
adaptiveCard.OnSubmit = function(action) { alert("Ow!"); }to
adaptiveCard.onExecuteAction = function(action) { alert("Ow!"); }
I tried this but not work..please other approach.
Please help me with this issue. Actually, I already try this OnSubmit but not work. can you suggest any other approaches?
Thanks for reply
@lokeshbansal1993 Matt's suggestion is correct. You need to set the onExecuteAction handler. OnSubmit doesn't exist. Your code should look something like this (in TypeScript, assuming you have importaed adaptivecards under the AdaptiveCards namespace):
import * as AdaptiveCards from "adaptivecards";
...
this.adaptiveCard.onExecuteAction = function(action: AdaptiveCards.Action) {
if (action instanceof AdaptiveCards.SubmitAction) {
// Do whatever you need to do. This example displays the value of the data property:
alert(JSON.stringify(action.data));
}
}
If the above doesn't work, please share what the error is or anything that can help us understand what's going wrong, thanks.
@lokeshbansal1993 Matt's suggestion is correct. You need to set the
onExecuteActionhandler. OnSubmit doesn't exist. Your code should look something like this (in TypeScript, assuming you have importaed adaptivecards under the AdaptiveCards namespace):import * as AdaptiveCards from "adaptivecards"; ... this.adaptiveCard.onExecuteAction = function(action: AdaptiveCards.Action) { if (action instanceof AdaptiveCards.SubmitAction) { // Do whatever you need to do. This example displays the value of the data property: alert(JSON.stringify(action.data)); } }If the above doesn't work, please share what the error is or anything that can help us understand what's going wrong, thanks.
Hi DcLaux,
Thanks for giving me solutions and your efforts but it's not work. see the code i used this:
import { Component, OnInit,Input, Output, EventEmitter, OnChanges, ViewChild, ElementRef } from '@angular/core';
import * as AdaptiveCards from "adaptivecards";
import * as $ from 'jquery';
@Component({
selector: 'app-cards',
templateUrl: './cards.component.html',
styleUrls: ['./cards.component.css']
})
export class CardsComponent implements OnInit {
@Input() cardsValue;
public adaptiveCard;
public renderCards;
public innerHTMLVal;
@ViewChild('cards') cards: ElementRef;
public item: HTMLElement;
constructor() {
this.adaptiveCard = new AdaptiveCards.AdaptiveCard();
}
ngOnInit() {
// this.adaptiveCard = new AdaptiveCards.AdaptiveCard();
// this.adaptiveCard.hostConfig = new AdaptiveCards.HostConfig({
// fontFamily: "Segoe UI, Helvetica Neue, sans-serif"
// // More host config options
// });
// Set the adaptive card's event handlers. onExecuteAction is invoked
// whenever an action is clicked in the card
this.adaptiveCard.onExecuteAction = function(action: AdaptiveCards.Action) {
if (action instanceof AdaptiveCards.SubmitAction) {
// Do whatever you need to do. This example displays the value of the data property:
alert(JSON.stringify(action.data));
}
}
// For markdown support you need a third-party library
// E.g., to use markdown-it, include in your HTML page:
// <script type="text/javascript" src="https://unpkg.com/markdown-it/dist/markdown-it.js"></script>
// And add this code to replace the default markdown handler:
// AdaptiveCards.processMarkdown = function(text) { return markdownit().render(text); }
// Parse the card payload
this.adaptiveCard.parse(this.cardsValue);
// let action = this.cardsValue[0].type
// console.log(a)
// Render the card to an HTML element:
this.renderCards = this.adaptiveCard.render();
this.cards.nativeElement.innerHTML=this.renderCards.innerHTML;
// console.log(a.actions)
// this.innerHTMLVal=this.renderCards;
// this.item = this.renderCards;;
// console.log('carddss');
// console.log(this.renderCards.actions)
// console.log(this.cardsValue)
// console.log(JSON.stringify(this.cardsValue))
}
}
please help me for accroding to this code
I'm really not quite sure what to say. It does work, I just tested it a moment ago to double check, using your card payload. Are you getting an error? If so what is it? Can you share what you see in the debug console?
can you please help me?
I want to how to use form type adaptive card in angular6 js and send what type of data to get filter result from a chatbot.
On Mon, Dec 3, 2018 at 10:23 PM David Claux [email protected] wrote:
I'm really not quite sure what to say. It does work, I just tested it a moment ago to double check, using your card payload. Are you getting an error? If so what is it? Can you share what you see in the debug console?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/AdaptiveCards/issues/2186#issuecomment-443782528, or mute the thread https://github.com/notifications/unsubscribe-auth/AinMSDD32Fs9ISKQdIGuFq0cCm7xan2qks5u1VcXgaJpZM4Yykoc .
-- Best regards,
Lokesh Kumar Sr. Software Engineer
I am happy to help, but you are not providing enough information. I am not able to reproduce the problem on my side, and have asked if you could send details about the possible errors you are getting from the browser's debug console.
Hi David,
Thank you so much for your help
Actually, I want to use adaptive cards in angular6. now we can show adaptive cards on the frontend but when show as a form adaptive cards but ..don't know what approach use to submit the form. actually, form submission not working in angular 6. can you share an example of angular 6 with form submission in adaptive cards.
so please share any help code to help.
On Tue, Dec 11, 2018 at 9:53 PM David Claux [email protected] wrote:
I am happy to help, but you are not providing enough information. I am not able to reproduce the problem on my side, and have asked if you could send details about the possible errors you are getting from the browser's debug console.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/AdaptiveCards/issues/2186#issuecomment-446264911, or mute the thread https://github.com/notifications/unsubscribe-auth/AinMSNlrA5ZinS1ZRHHqoic9jYneYVxHks5u39vvgaJpZM4Yykoc .
-- Best regards,
Lokesh Kumar Sr. Software Engineer
Hi David,
Thank you so much for your help
Now action submits work fine. thanks. Now after submitting action what data send to chatbot API. please help with that.
Thank you so much again :)
On Wed, Dec 12, 2018 at 12:14 PM Lokesh Bansal [email protected] wrote:
Hi David,
Thank you so much for your help
Actually, I want to use adaptive cards in angular6. now we can show adaptive cards on the frontend but when show as a form adaptive cards but ..don't know what approach use to submit the form. actually, form submission not working in angular 6. can you share an example of angular 6 with form submission in adaptive cards.
so please share any help code to help.
On Tue, Dec 11, 2018 at 9:53 PM David Claux [email protected] wrote:
I am happy to help, but you are not providing enough information. I am not able to reproduce the problem on my side, and have asked if you could send details about the possible errors you are getting from the browser's debug console.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/AdaptiveCards/issues/2186#issuecomment-446264911, or mute the thread https://github.com/notifications/unsubscribe-auth/AinMSNlrA5ZinS1ZRHHqoic9jYneYVxHks5u39vvgaJpZM4Yykoc .
-- Best regards,
Lokesh Kumar Sr. Software Engineer
-- Best regards,
Lokesh Kumar Sr. Software Engineer
hi Lokesh, I am facing same problem, how did u solve the action.submit issue?
hi Lokesh, I am facing same problem, how did u solve the action.submit issue?
Same here, with Angular 7, buttons are dead ... Any solution ?
@lokeshbansal1993 FYI- mind helping out @Sushil1091Jes ?
Can you sent your code for me then give to best solution.? Actually I explored this issue takes more time but will do this.
On Thu 27 Jun, 2019, 5:27 AM shalinijoshi19 <[email protected] wrote:
@lokeshbansal1993 https://github.com/lokeshbansal1993 FYI- mind helping out @Sushil1091Jes https://github.com/Sushil1091Jes ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/AdaptiveCards/issues/2186?email_source=notifications&email_token=AIU4YSEYLZLLSMLN3EFN3GTP4P66NA5CNFSM4GGKJIOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYVEHSY#issuecomment-506086347, or mute the thread https://github.com/notifications/unsubscribe-auth/AIU4YSBSXCBTJTLE47JW7TDP4P66NANCNFSM4GGKJIOA .
Can you sent your code for me then give to best solution.? Actually I explored this issue takes more time but will do this.
On Tue 11 Dec, 2018, 6:11 PM Lokesh Bansal <[email protected] wrote:
can you please help me?
I want to how to use form type adaptive card in angular6 js and send what type of data to get filter result from a chatbot.
On Mon, Dec 3, 2018 at 10:23 PM David Claux [email protected] wrote:
I'm really not quite sure what to say. It does work, I just tested it a moment ago to double check, using your card payload. Are you getting an error? If so what is it? Can you share what you see in the debug console?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/AdaptiveCards/issues/2186#issuecomment-443782528, or mute the thread https://github.com/notifications/unsubscribe-auth/AinMSDD32Fs9ISKQdIGuFq0cCm7xan2qks5u1VcXgaJpZM4Yykoc .
-- Best regards,
Lokesh Kumar Sr. Software Engineer
i want to integrate the adaptive cards in angular. I was facing the same issue the buttons were dead, can you please share the code ?
this.adaptiveCard.parse(this.cardsValue); // let action = this.cardsValue[0].type // console.log(a) // Render the card to an HTML element: this.renderCards = this.adaptiveCard.render(); // this.cards.nativeElement.innerHTML=this.renderCards.innerHTML; this.renderer.appendChild(this.cards.nativeElement, this.renderCards); this.adaptiveCard.onExecuteAction = (action) => { // alert(JSON.stringify(action.data)); console.log('Action'); console.log(action.data); };
On Tue, Jul 2, 2019 at 4:33 PM SriRakesh [email protected] wrote:
i want to integrate the adaptive cards in angular, can you please share the code ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/AdaptiveCards/issues/2186?email_source=notifications&email_token=AIU4YSAJJWJAVPIBEJTCAX3P5MYYDA5CNFSM4GGKJIOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZA4SHQ#issuecomment-507627806, or mute the thread https://github.com/notifications/unsubscribe-auth/AIU4YSFGC7OZQBKSRNMZY63P5MYYDANCNFSM4GGKJIOA .
-- Best regards,
Lokesh Kumar Sr. Software Engineer
this.adaptiveCard.parse(this.cardsValue); // let action = this.cardsValue[0].type // console.log(a) // Render the card to an HTML element: this.renderCards = this.adaptiveCard.render(); // this.cards.nativeElement.innerHTML=this.renderCards.innerHTML; this.renderer.appendChild(this.cards.nativeElement, this.renderCards); this.adaptiveCard.onExecuteAction = (action) => { // alert(JSON.stringify(action.data)); console.log('Action'); console.log(action.data); }; … On Tue, Jul 2, 2019 at 4:33 PM SriRakesh @.***> wrote: i want to integrate the adaptive cards in angular, can you please share the code ? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2186?email_source=notifications&email_token=AIU4YSAJJWJAVPIBEJTCAX3P5MYYDA5CNFSM4GGKJIOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZA4SHQ#issuecomment-507627806>, or mute the thread https://github.com/notifications/unsubscribe-auth/AIU4YSFGC7OZQBKSRNMZY63P5MYYDANCNFSM4GGKJIOA . -- Best regards, Lokesh Kumar Sr. Software Engineer
Hai Lokesh,
From the above code you have taken the 'renderer' variable, can you explain me why?. i didn't understand that part of it. This is my code, i need to perform Action for 'Action.Submit' and 'Action.OpenUrl'. So, do you know how can i do that.
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; import * as AdaptiveCards from "adaptivecards"; import { HttpClient } from '@angular/common/http';
@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit {
cards: any; output: any; textArea: any;
@ViewChild('adaptiveCards') AdaptiveCards: ElementRef;
constructor(private http: HttpClient) { this.cards = new AdaptiveCards.AdaptiveCard(); }
ngOnInit() {
}
onClickConvert(json: any) { let jsonText = JSON.parse(json.value); console.log(jsonText) this.cards.parse(jsonText); console.log(this.cards); this.output = this.cards.render(); console.log(this.output); this.AdaptiveCards.nativeElement.innerHTML = this.output.innerHTML;
} }
this.AdaptiveCards.nativeElement.innerHTML = this.output.innerHTML;
this line replace by this this.renderer.appendChild(this.AdaptiveCards.nativeElement, this.output.); then you can try
On Tue, Jul 2, 2019 at 7:05 PM SriRakesh [email protected] wrote:
this.adaptiveCard.parse(this.cardsValue); // let action = this.cardsValue[0].type // console.log(a) // Render the card to an HTML element: this.renderCards = this.adaptiveCard.render(); // this.cards.nativeElement.innerHTML=this.renderCards.innerHTML; this.renderer.appendChild(this.cards.nativeElement, this.renderCards); this.adaptiveCard.onExecuteAction = (action) => { // alert(JSON.stringify(action.data)); console.log('Action'); console.log(action.data); }; … <#m_-783076987816765731_> On Tue, Jul 2, 2019 at 4:33 PM SriRakesh @.***> wrote: i want to integrate the adaptive cards in angular, can you please share the code ? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2186 https://github.com/microsoft/AdaptiveCards/issues/2186?email_source=notifications&email_token=AIU4YSAJJWJAVPIBEJTCAX3P5MYYDA5CNFSM4GGKJIOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZA4SHQ#issuecomment-507627806>, or mute the thread https://github.com/notifications/unsubscribe-auth/AIU4YSFGC7OZQBKSRNMZY63P5MYYDANCNFSM4GGKJIOA . -- Best regards, Lokesh Kumar Sr. Software Engineer
Hai Lokesh,
This is my code, i need to perform Action for 'Action.Submit' and 'Action.OpenUrl'. So, do you know how can i do that.
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; import * as AdaptiveCards from "adaptivecards"; import { HttpClient } from '@angular/common/http';
@component https://github.com/component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit {
cards: any; output: any; textArea: any;
@ViewChild https://github.com/ViewChild('adaptiveCards') AdaptiveCards: ElementRef;
constructor(private http: HttpClient) { this.cards = new AdaptiveCards.AdaptiveCard(); }
ngOnInit() {
}
onClickConvert(json: any) { let jsonText = JSON.parse(json.value); console.log(jsonText) this.cards.parse(jsonText); console.log(this.cards); this.output = this.cards.render(); console.log(this.output); this.AdaptiveCards.nativeElement.innerHTML = this.output.innerHTML;
} }
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/AdaptiveCards/issues/2186?email_source=notifications&email_token=AIU4YSDREWDJS2OASTS5433P5NKTJA5CNFSM4GGKJIOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZBJHRI#issuecomment-507679685, or mute the thread https://github.com/notifications/unsubscribe-auth/AIU4YSDOKRNGR4TWBESBWWTP5NKTJANCNFSM4GGKJIOA .
-- Best regards,
Lokesh Kumar Sr. Software Engineer
@lokeshbansal1993 @dclaux
Hello , I am facing similar issue, submit action is not working for the below code. But works fine in emulator and webchat.
let adaptiveCard = new AdaptiveCards.AdaptiveCard(); adaptiveCard.hostConfig = new AdaptiveCards.HostConfig({ fontFamily: "Segoe UI, Helvetica Neue, sans-serif" }); adaptiveCard.parse(card); let renderedCard = adaptiveCard.render(); var elementHtml = renderedCard.outerHTML; this.adaptiveCardHtml = this.sanitizer.bypassSecurityTrustHtml(elementHtml)
{ "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "speak": "Your Working Days values are", "version": "1.0", "body": [ { "type": "TextBlock", "text": "Working Days for Feb 01, 2020 - Feb 29, 2020", "wrap": true }, {}, { "type": "ColumnSet", "columns": [ { "type": "Column", "width": 100, "items": [ { "type": "TextBlock", "text": "4 days", "weight": "Bolder", "wrap": true, "spacing": "None" } ] } ], "separator": true }, { "type": "ColumnSet", "columns": [ { "type": "Column", "width": "stretch", "items": [ { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "ThumbsUp", "data": { "userFeedback": "positive", "conId": "901ea151-48ad-11ea-b596-9793596ce318|livechat", "activityId": "9b5bfae0-48ad-11ea-83a3-23f4bfa04a95" } } ] } ] }, { "type": "Column", "width": "stretch", "items": [ { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "ThumbsDown", "data": { "userFeedback": "negative", "conId": "901ea151-48ad-11ea-b596-9793596ce318|livechat", "activityId": "9b5bfae0-48ad-11ea-83a3-23f4bfa04a95" } } ] } ] } ] } ] }