Hello I was making a website in which I want user to see their input in preview sections.
so if someone type: <h1>HELLO WORLD!</h1> then below preview section should show HELLO WORLD! as heading 1 in ejs.
<div class="form-group">
<label><i class="fad fa-texts"></i> Long Description<span style="color: rgb(175, 22, 22)">*</span>
<p class="text-muted">(Html supported but markdown not supported)</p>
</label>
<textarea name="longDesc" onkeypress="dis()" id="longDesc" class="form-control" minlength="300" required="required" style="width: 100%; height: 300px;"></textarea>
<textarea name="liveDesc" id="liveDesc" class="form-control" minlength="300" required="required" style="width: 100%; height: 300px;" disabled></textarea>
</div>
<script>
function dis (){
var botdesc = document.getElementById("longdesc");
var visualizer = document.getElementById("livedesc");
botdesc.addEventListener("keyup",async (e) => {
const dirtyhtml = marked(botdesc.value.replaceAll(/>+/g, ">").replaceAll(/<+/g, "<"));
const noicehtml = sanitizeHtml(dirtyhtml, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['discord-message','discord-messages', 'img','iframe', 'style', 'h1', 'h2', 'link', 'mark', 'svg', 'span']),
allowVulnerableTags: true,
allowedAttributes: {
'*': ["*"]
}
});
visualizer.innerHTML = noicehtml;
});
}
example below:
https://imgur.com/a/mSD6sKc
Using vanilla JavaScript, you can get a value from input or textarea and then push it in any element as HTML child nodes
For example, you have this HTML:
<textarea id="text" onkeyup="onChange()"></textarea>
<div id="htmlView"></div>
In this example, we are going to get value from the textarea and then push HTML nodes in the htmlView div
For this, we can write a function:
function onChange() {
// get value
const text = document.getElementById("text").value;
// set plain text as HTML nodes
document.getElementById("htmlView").innerHTML = text;
}
And, as you can see, it works
function onChange() {
const text = document.getElementById("text").value;
document.getElementById("htmlView").innerHTML = text;
}
<textarea id="text" onkeyup="onChange()"></textarea>
<div id="htmlView"></div>
Related
According to the docs and code i have looked at, this is how forms are created to add card or accept cards
var style = {
base: {
fontSize: "16px",
color: "#32325d",
fontFamily:
"-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif",
fontSmoothing: "antialiased",
"::placeholder": {
color: "rgba(0,0,0,0.4)"
}
}
};
var card = elements.create("card", { style: style });
card.mount("#card-element");
this is according to the docs https://stripe.com/docs/stripe-js and the code example given https://github.com/stripe-samples/saving-card-without-payment/blob/master/client/script.js
How can i format the new forms so that i have the email,card holder name, card number,expiration and cvv on a different line?
I am using twitter bootstrap. Also how can i leave out the postal code part?
I just recently figured this out for a project I am working on and it was more challenging than I was expecting. The example below is creating a payment method for a metered billing scenario. The hardest thing for me to comprehend during the learning process was in the createPaymentMethod you will notice that it is only passed the cardNumber element and then the stripe library figures out the other elements automatically.
HTML:
<div class="row">
<div class="col-md-6 mb-3">
<label for="cc-name">Name on card</label>
<input type="text" class="form-control" id="cc-name" placeholder="" required>
<small class="text-muted">Full name as displayed on card</small>
<div class="invalid-feedback">
Name on card is required
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<div id="card-number" style="border:2px solid gray;"></div>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<div id="card-exp" style="border:2px solid gray;"></div>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<div id="card-cvc" style="border:2px solid gray;"></div>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<button id="submit-button" type="button">
<div class="spinner hidden" id="spinner"></div>
<span id="button-text">Pay</span>
</button>
</div>
</div>
Javascript:
$(document).ready(function () {
// Create a Stripe client
var stripe = Stripe('YOUR KEY');
// Create an instance of Elements
var elements = stripe.elements({
locale: 'auto'
});
let displayError = document.getElementById('card-error');
var style = {
base: {
color: "#32325d",
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: "antialiased",
fontSize: "16px",
"::placeholder": {
color: "#aab7c4"
}
},
invalid: {
color: "#fa755a",
iconColor: "#fa755a"
}
};
var cardNumber = elements.create("cardNumber", { style: style });
cardNumber.mount("#card-number");
var cardExp = elements.create("cardExpiry", { style: style });
cardExp.mount("#card-exp");
var cardCvc = elements.create("cardCvc", { style: style });
cardCvc.mount("#card-cvc");
cardNumber.on('change', showCardError);
cardExp.on('change', showCardError);
cardCvc.on('change', showCardError);
function showCardError(event) {
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
}
$("#submit-button").on("click", function () {
createPaymentMethod(cardNumber, 'CUSTOMER ID', 'PRODUCT ID');
});
function createPaymentMethod(cardElement, customerId, priceId) {
return stripe
.createPaymentMethod({
type: 'card',
card: cardElement,
billing_details: {
name: $('#cc-name').val()
}
})
.then((result) => {
if (result.error) {
displayError.textContent = result.error;
} else {
console.log('SUCCESS');
console.log(result);
}
});
}
});
I am new to angular when I was trying to put the form validation to the text field form was present inside *ngFor loop, So validation is working but it shows to every field but I want validation the particular field only , so please help me How to put the validation to the particular form field.
**HTML**
<div class="container" *ngFor="let post of posts; let i = index">
<div class="row">
<div class="col-md-12" style="display: block; ">
<form [formGroup]="commentForm" method="post" enctype="multipart/form-data" (ngSubmit)="comment_Submit(post.user_id, post.post_id,
commentForm)">
<div class="form-group">
<input type="text" class="form-control" name="comment{{i}}" formControlName="comment" id="comment"
placeholder="Enter comments" cols="40" rows="5" spellcheck="true"
style="width:100%; height: auto; border: 1px solid #ada5a5; border-radius: 4px; outline: none; user-select: text; white-space: pre-wrap; overflow-wrap: break-word; "
[ngClass]="{'form-control': true,
'is-invalid': !f.comment.valid,
'is-valid':f.comment.valid}">
<div *ngIf="f.comment.errors?.minlength && f.comment.touched" class="text-danger">Comment
should be at
least 2 characters.</div>
</div>
<button type="submit" class="btn-sm btn-success" [disabled]="!commentForm.valid">Comment</button>
</form>
</div>
</div>
</div>
**TypeScript**
export class PostsComponent implements OnInit {
get f() { return this.commentForm.controls; }
constructor(private userService: UserService, private formBuilder: FormBuilder,
private alerts: AlertsService) {
this.commentFormValidation();
}
commentForm: FormGroup;
ngOnInit() { }
commentFormValidation() {
this.commentForm = this.formBuilder.group({
comment: [null, [Validators.required, Validators.minLength(2)]]
});
}
Your posts all share the one and same form. If you have n amount of posts, you need n amount of forms. We can achieve this by creating an array (just a JS array) of formgroups, the same length that your posts array is...
formsArr = [];
constructor(private fb: FormBuilder) { }
ngOnInit() {
this.posts.forEach((x) => {
this.formsArr.push(this.fb.group({
comment: this.fb.control('', [Validators.required, Validators.minLength(2)])
}))
})
}
Then in your template you iterate formsArr. You probably need access to some stuff in your posts array... so we add the index in iteration, therefore you can access the specific post with posts[i]. Also remove method="post" from your form:
<div *ngFor="let a of formsArr; let i = index">
<form [formGroup]="a" (ngSubmit)="onSubmit(a.value, posts[i].user_id)">
<input formControlName="comment" />
<small *ngIf="a.hasError('minlength', 'comment') && a.get('comment').touched">
Needs to be 2 letters
</small>
<button type="submit" [disabled]="!a.valid">Comment</button>
</form>
</div>
StackBlitz
I have a problem with the input text on onsen alert dialog
when I click OK button dialog not hide
how to get password value from dialog input tag
<ons-button modifier="tappable" onclick="
ons.createAlertDialog('alert.html').then(function(alertDialog) {
alertDialog.show();
});
"
>Test2</ons-button>
<script type="text/ons-template" id="alert.html">
<ons-alert-dialog animation="default" cancelable>
<div class="alert-dialog-title">Warning!</div>
<div class="alert-dialog-content">
<input id="password" ng-model="password" class="text-input " type="number"
pattern="[0-9]*" inputmode="numeric" placeholder="password" value="" autofocus>
</div>
<div class="alert-dialog-footer">
<button class="alert-dialog-button" onclick="alertDialog.hide()">OK</button>
</div>
</ons-alert-dialog>
</script>
You will need to add your data to a global variable or push it to the factory as it appears you are using Angular.
Also, you need to register your dialogue to a controller / variable as well so you can close it. The demo on the tutorial site is for vanilla right now, but the concept is the same.
Here is how this works: http://tutorial.onsen.io/?framework=vanilla&category=Reference&module=dialog
JS:
var showDialog = function(id) {
document
.getElementById(id)
.show();
};
var hideDialog = function(id) {
document
.getElementById(id)
.hide();
};
var fromTemplate = function() {
var dialog = document.getElementById('dialog-3');
if (dialog) {
dialog.show();
}
else {
ons.createDialog('dialog.html')
.then(function(dialog) {
dialog.show();
});
}
};
Markup:
<ons-page>
<ons-toolbar>
<div class="center">Dialogs</div>
</ons-toolbar>
<ons-list>
<ons-list-header>Showing dialogs</ons-list-header>
<ons-list-item tappable onclick="showDialog('dialog-1')">Simple dialog</ons-list-item>
<ons-list-item tappable onclick="showDialog('dialog-2')">Alert dialog</ons-list-item>
<ons-list-item tappable onclick="fromTemplate()">From template</ons-list-item>
<ons-list-header>Notifications</ons-list-header>
<ons-list-item tappable onclick="ons.notification.alert('Hello, world')">Alert</ons-list-item>
<ons-list-item tappable onclick="ons.notification.confirm({message: 'Are you ready?'})">Confirmation</ons-list-item>
<ons-list-item tappable onclick="ons.notification.prompt({message: 'What is your name?'})">Prompt</ons-list-item>
</ons-list>
</ons-page>
<ons-dialog id="dialog-1">
<div style="text-align: center; padding: 10px;">
<p>
This is a dialog.
<p>
<p>
<ons-button onclick="hideDialog('dialog-1')">Close</ons-button>
</p>
</div>
</ons-dialog>
<ons-alert-dialog id="dialog-2">
<div class="alert-dialog-title">Warning!</div>
<div class="alert-dialog-content">
An error has occurred!
</div>
<div class="alert-dialog-footer">
<button class="alert-dialog-button" onclick="hideDialog('dialog-2')">Cancel</button>
<button class="alert-dialog-button" onclick="hideDialog('dialog-2')">OK</button>
</div>
</ons-alert-dialog>
<ons-template id="dialog.html">
<ons-dialog id="dialog-3">
<div style="text-align: center; padding: 10px;">
<p>
This dialog was created from a template.
<p>
<p>
<ons-button onclick="hideDialog('dialog-3')">Close</ons-button>
</p>
</div>
</ons-dialog>
</ons-template>
User.groovy
class User {
String firstName
String lastName
String email
Integer age
static constraints = {
firstName blank:false, nullable:false, maxSize:50
lastName blank:false, nullable:false, maxSize:50
email email:true, blank:false, nullable:false
age min:18, blank:false, nullable:false
}
}
UserController.groovy
class UserController {
static scaffold = true
def index() {
redirect(action: 'search')
}
def search() {
}
def searchTable(){
def list = User.list()
[ list:list ]
render(template: 'searchTable', model:[ list : list ])
}
}
search.gsp
<h1>Please enter First Name or Last Name for search</h1>
<div id="lb">
<label for="first_name">First Name Search:</label>
<g:textField name="first_name"/><br/>
<br/><br/>
<label for="last_name">Last Name Search:</label>
<g:textField name="last_name"/><br/>
</div>
<div id="insertSearchResultsHere">
</div>
_searchTable.gsp
<%# page import="com.myapp.User" contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta name="layout" content="main">
<title>Users</title>
<style>
table, td, th {
border: 1px solid black;
}
td {
padding: 15px;
}
table{
width: 100%;
}
th {
background-color: green;
color: white;
text-align: left;
height: 50px;
}
</style>
</head>
<body>
<div id="list-menu" class="content scaffold-list" role="main">
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<g:each in="${list}" var="user" status="i">
<tr>
<td>${user.firstName}</td>
<td>${user.lastName}</td>
<td>${user.email}</td>
<td>${user.age}</td>
</tr>
</g:each>
</tbody>
</table>
</div>
</body>
</html>
How I can search in search.gsp by firstName or lastName and return data form serachTable tamplate (show in section id="insertSearchResultsHere"), using remoteFunction in grails.
I think that remoteFunction won't work for you in this case - at least not easily, because you need to gather the information provided by the user in the input fields.
What you need in my opinion is a formRemote - after all, you are rendering a search form - you just didn't add the form tag yet :) . So:
surround your input fields by a g:formRemote tag.
add an input submit before the end of the form. It will be used to trigger the form submit (and thus the search as well).
For this, you only have to change search.gsp:
<h1>Please enter First Name or Last Name for search</h1>
<div id="lb">
<g:formRemote name="userSearch" url="${[controller: 'user', action: 'searchTable']}" method="GET" update="insertSearchResultsHere">
<label for="firstName">First Name Search:</label>
<g:textField name="firstName"/><br/>
<br/><br/>
<label for="lastName">Last Name Search:</label>
<g:textField name="lastName"/><br/>
<input type="submit" value="Search" />
</g:formRemote>
</div>
<div id="insertSearchResultsHere">
</div>
Additionally, you need to actually search by the provided first and last names in the controller:
def searchTable(){
def list = User.withCriteria {
and {
if (params.firstName) {
eq('firstName', params.firstName)
}
if (params.lastName) {
eq('lastName', params.lastName)
}
}
}
render(template: 'searchTable', model:[ list : list ])
}
Desired Functionality
Two input fields that both have drag and drop functionality.
With the generated 'value' div beneath each input field.
Current Functionality
Four generated 'value' divs are being created instead of two.
Plugin Demo (select the Plugins tab and scroll to "drag_drop")
http://brianreavis.github.io/selectize.js
What I've Tried:
http://jsfiddle.net/rwone/E72q5/5/
HTML Form
<!-- simple html form - a container with left and right divs -->
<div class="my_form_page_content">
<form id="my_form_name" name="my_form_name">
<div class="my_form_container">
<div class="my_form_left">
<p>field one</p>
<p>field two</p>
</div>
<div class="my_form_right">
<div class="input_wrapper">
<input type="text" id="input-sortable-1" class="input-sortable demo-default" value="input 1 value, lala1, lala1a">
</div>
<div class="input_wrapper">
<input type="text" id="input-sortable-2" class="input-sortable demo-default" value="input 2 value, lala2, lala2a">
</div>
</div>
<div class="my_form_button">
<button type="submit">submit</button>
</div>
</div>
</form>
</div>
jQuery
// aim: to have a unique 'value' div beneath each input field.
// selectize drag and drop functionality
$('.input-sortable').selectize({
plugins: ['drag_drop'],
delimiter: ',',
persist: false,
create: function(input) {
return {
value: input,
text: input
}
}
});
// the js that should add a 'value' div after each input box
$(function() {
var $wrapper = $('.input_wrapper');
// show current input values
$('select.selectized,input.selectized', $wrapper).each(function() {
var $container = $('<div>').addClass('value').html('Current Value: ');
var $value = $('<span>').appendTo($container);
var $input = $(this);
var update = function(e) { $value.text(JSON.stringify($input.val())); }
$(this).on('change', update);
update();
$container.insertAfter($wrapper);
});
});
i have done a fiddle as per your input.
http://jsfiddle.net/Shinov/csNgy/
$input.parents(".field-row:first").append($container)