I have this code
var pass = prompt("Please enter your password:", "");
I want to make this prompt through Sweet Alert and save it in variable pass. So far I have done this but I don't know how to save it in a variable.
swal({
content: {
element: "input",
attributes: {
placeholder: "Type your password",
type: "password",
},
},
});
You can do something like:
var pass = null;
swal({
content: {
element: "input",
attributes: {
placeholder: "Type your password",
type: "password",
}
}
})
.then(function(value) {
pass = value;
});
Related
Basically, I'm converting one of my regular commands into a slash command. It's just an embedded response, but the issue is that it says "This interaction failed". I read on deferReply(), but deferReply doesn't work for me at all, it's supposed to say "bot is thinking.." but doesn't. It does the 3 second "Sending command..." then fails.
Code:
const { SlashCommandBuilder, EmbedBuilder } = require('#discordjs/builders');
const wait = require('node:timers/promises').setTimeout;
let questions = [
{
title: "some array you got there!",
},
]
let suggest = ["some array you got there!",]
let q = questions[Math.floor(Math.random()*(questions.length))];
let s = suggest[Math.floor(Math.random()*(suggest.length))];
module.exports = {
data: new SlashCommandBuilder()
.setName('topic')
.setDescription('gives topics'),
async execute(interaction, message) {
interaction.deferReply()
const user = message.mentions.users.first() || message.author;
const embed = {
title: `**${q.title}**`,
author: {
name: 'chat topic:',
icon_url: user.avatarURL(),
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
},
footer: {
text: `topic requested by: ${message.author.username} ${s}`,
icon_url: '',
},
color: 0x7732a8,
}
interaction.editReply({ embeds: [embed] });
}}
There's no issues in console, I tried to log, still nothing. Just "This interaction failed."
I have created Dialog in AddButtonEntryPoint.js file and I want to access that variable in Form.js file to hide the dialog after click on Submit button So, How can i call.
Here is the code which i have written
AddButtonEntryPoint.js
var w = new Form({});
var d = new Dialog({
id: 'FormDialog',
title: "Bridge Form",
style: "width: 270px; height: 270px;",
content: w,
onHide: function() {
// To prevent destroying the dialog before the animation ends
setTimeout(lang.hitch(this, 'destroyRecursive'), 0);
}
});
d.show();
};
Form.js
return declare( "mypackage.MyForm", Form, {
repotextbox: new TextBox({
name: "text",
placeHolder: "Enter text here."
} , dojo.doc.createElement('input')),
DFMtextbox: new TextBox({
name: "text",
placeHolder: "Enter text here."
} , dojo.doc.createElement('input')),
submitButton: new Button({
type: "submit",
label: "Submit"
}),
constructor: function(args) {
declare.safeMixin(this, args);
},
onSubmit: function() {
var repositoryID = this.repotextbox.get('value');
xhr("https://samples.openweathermap.org/data/2.5/weather?q={repositoryID}",{
// The URL of the request
method: "GET",
handleAs: "json",
}).then(
function(data){
alert(data.success + " " + JSON.stringify(data));
},
function(err){
alert( "Your message could not be sent, please try again.");
});
},
});
}
);
In form.js file, Under onSubmit function I have to hide the dialog created in AddButtonEntryPoint.js when the user click on Submit button.
In Form.js you have to add a property that will reference the Dialog instance
return declare( "mypackage.MyForm", Form, {
myDialog: null,
// etc
}
Then in AddButtonEntryPoint you can either set this property when you initialize w if you put it after:
var d = new Dialog({
id: 'FormDialog',
title: "Bridge Form",
style: "width: 270px; height: 270px;",
content: w,
onHide: function() {
// To prevent destroying the dialog before the animation ends
setTimeout(lang.hitch(this, 'destroyRecursive'), 0);
}
});
var w = new Form({
myDialog: d
});
or you can keep it as it is and call w.set("myDialog", d); later - but in this case any code in postCreate that requires the dialog will not run.
Hope this helps!
I need your help to adapt a code that displays if a username is already taken.
This code is working :
$(document).ready(function()
{
$("#name").keyup(function()
{
var name = $(this).val();
$.post( "username-check.php", { name: $("#name").val() }, function (data){
if(data=='1'){
//the php post result is equal to '1' if the username is already taken.
// This actualy display "1" in the form if the username is taken.
$("#result").html(data);
}
}); //function(data)
});
})
I got this code from a website, to check and validate the inputs of my form
$('document').ready(function()
{
// Check and validate the username input
var nameregex = /^[a-zA-Z0-9 ]+$/;
$.validator.addMethod("validname", function( value, element ) {
return this.optional( element ) || nameregex.test( value );
});
/* To check if the username is taken I think I have to add something like that :
var checkusernameregex = ??????;
$.validator.addMethod("checkusername", function( value, element ) {
return this.optional( element ) || checkusernameregex.test( value );
}); */
$("#register-form").validate({
rules:
{
name: {
required: true,
validname: true,
//chekusername : true,
minlength: 5,
maxlength: 25
}
},
messages:
{
name: {
required: "Please choose a username",
validname: "Username can only have alphanumerical characters ",
//checkusername: "Username already taken";
minlength: "Username is too short"
}
},
});
//to display errors code, but not needed for my actual request
Thank you
I have the following form. I need to print the value the user entered for textfiled uname ? How can i do this ?
Ext.create('Ext.form.Panel', {
title: 'Basic Form',
renderTo: Ext.getBody(),
bodyPadding: 5,
width: 350,
// Any configuration items here will be automatically passed along to
// the Ext.form.Basic instance when it gets created.
// The form will submit an AJAX request to this URL when submitted
url: 'save-form.php',
items: [{
fieldLabel: 'NAME',
name: 'uname'
}],
buttons: [{
text: 'Submit',
handler: function() {
// The getForm() method returns the Ext.form.Basic instance:
var form = this.up('form').getForm();
if (form.isValid()) {
// CONSOLE.LOG (FORM VALUES) ///////////////////////////////////////
}
}
}]
});
Use the getValues method to get an object containing all of the field values in the form:
var form = this.up('form').getForm();
if (form.isValid()) {
var values = form.getValues();
// log all values.
console.log(values);
// log uname value.
console.log(values['uname']);
}
Alternatively, use the findField method to access a specific field within the form:
var form = this.up('form').getForm();
if (form.isValid()) {
// log uname value.
var field = form.findField('uname');
console.log(field.getValue());
}
Example: http://jsfiddle.net/5hndW/
I have a store as follows.
var eventsStore = new Ext.data.Store({
model: 'Event',
sorters: [{
property: 'OccurringOn',
direction: 'DESC'
}],
proxy: {
type: 'ajax',
url: BaseURL + 'Events.php',
api: {
read: BaseURL + 'Events.php',
create: BaseURL + 'Events.php'
},
reader: {
type: 'xml',
root: 'Events',
record: 'Event'
},
writer: {
type: 'xml',
writeAllFields: false,
root: 'Events',
record: 'Event'
}
},
getGroupString: function(record) {
if (record && record.data.OccurringOn) {
console.log(record.get('OccurringOn'));
return record.get('OccurringOn').toDateString();
}
else {
return '';
}
}
});
I also have a List view which gets all Events fine. I have a form which allows user to add new event and I have FormPanel for it. The FormPanel has Toolbar which has Save button which when clicked will do following.
var eventCard = It's a card
var newEventCard = eventCard.items.items[1];
var currentEvent = newEventCard.getRecord();
newEventCard.updateRecord(currentEvent);
var errors = currentEvent.validate();
// here I check errors and prompt user about them
var eventList = eventCard.items.items[0].items.items[0];
var eventStore = eventList.getStore();
eventStore.add(currentEvent);
eventStore.sync();
eventStore.sort( [ { property: 'OccurringOn', direction: 'DESC' } ] );
eventList.refresh();
The above code adds two empty rows to the MySQL database and copies the event list view items with 3 empty new items. Why this is the behavior and what I am missing?
If you can tell me what parameters are sent as POST to the Events.php when I sync that would much appreciated.
It was my fault I figured out. I was echo'ing when there was POST request to the service.