I have a problem in AMP page. I want to build a page with AutoComplete list selection like jquery AutoComplete.
Amp give Example for Autocomplete Selection. But there is a problem. I have API with POST Method in this example I don't know how to set Request method Post in it with a different origin.
<div class="form-item city-state">
<label>City</label>
<input name="city"
type="text"
on="
input-debounced:
AMP.setState({
query: event.value,
showDropdown: event.value,
}),
autosuggest-list.show;
tap:
AMP.setState({
query: query == null ? '' : query,
showDropdown: 'true'
}),
autosuggest-list.show"
[value]="query || ''"
value=""
required
autocomplete="off" />
</div>
<div class="suggest">
<div class="autosuggest-container hidden"
[class]="(showDropdown && query) ?
'autosuggest-container' :
'autosuggest-container hidden'">
<amp-list class="autosuggest-box"
layout="fixed-height"
height="120"
src="/advanced/autosuggest/search_list"
[src]="query ?
autosuggest.endpoint + query :
autosuggest.emptyAndInitialTemplateJson"
id="autosuggest-list">
<template type="amp-mustache">
<amp-selector id="autosuggest-selector"
keyboard-select-mode="focus"
layout="container"
on="
select:
AMP.setState({
query: event.targetOption,
showDropdown: false
}),
autosuggest-list.hide">
{{#results}}
<div class="select-option no-outline"
role="option"
tabindex="0"
on="tap:autosuggest-list.hide"
option="{{.}}">{{.}}</div>
{{/results}} {{^results}}
<div class="select-option {{#query}}empty{{/query}}">
{{#query}}Sorry! We don't ship to your city 😰{{/query}}
</div>
{{/results}}
</amp-selector>
</template>
</amp-list>
</div>
</div>
<amp-state id="autosuggest">
<script type="application/json">
{
"endpoint": "/advanced/autosuggest/search_list?q=",
"emptyAndInitialTemplateJson": [{
"query": "",
"results": []
}]
}
</script>
</amp-state>
Related
Long time listener, first time caller. I've been practicing coding for ~1 year now and I'm currently trying to build a small CRUD app in Grails. For the past 3-4 weeks I have been unable to update records in the h2 database that Grails comes packaged with. I'm read many articles online, sifted through Stack Overflow, and even purchased the book 'Grails in Action' as a reference. Each resource makes me believe this should be relatively easy. I'm not sure if my issue is in my view (maybe how I'm posting the data), in my controller, or possibly in my application.yml. Below is my HTML, javascript, controller, domain, and application.yml code. Any help is GREATLY appreciated.
A few items to note:
1) When an update is executed, Grails validates with zero errors.
2) The update action prints the object's new attributes to the console, but the database isn't updated.
HTML - note, javascript function is used to change readOnly attributes from true to false
<form method="POST" action="../update">
<!--hidden field for contractor id-->
<input name="id" value="${params.id}" hidden>
<div class="row">
<div class="col-15">
<label for="name">Name:</label>
</div>
<div class="col-40">
<input class="readOnly" type="text" id="name" name="name" value="${params.name}" readonly>
</div>
<div class="editIcon">
<i id="editIcon" class="far fa-edit" title="Edit Contractor"></i>
</div>
</div>
<div class="row">
<div class="col-15">
<label for="street">Street:</label>
</div>
<div class="col-40">
<input class="readOnly" type="text" id="street" name="street" value="${params.street}" readonly>
</div>
</div>
<div class="row">
<div class="col-15">
<label for="city">City:</label>
</div>
<div class="col-40">
<input class="readOnly" type="text" id="city" name="city" value="${params.city}" readonly>
</div>
</div>
<div class="row">
<div class="col-15">
<label for="state">State:</label>
</div>
<div class="col-15 removeLeftPadding">
<select id="state" name="state" disabled>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
</select>
</div>
<div class="col-05 zip">
<label for="zip">Zip:</label>
</div>
<div class="col-13">
<input class="readOnly" type="text" id="zip" name="zip" value="${params.zip}" readonly>
</div>
</div>
<div class="row">
<div class="col-15">
<label for="paymentType">Payment Type:</label>
</div>
<div>
<select id="paymentType" name="paymentType" disabled>
<option value="1">ACH</option>
<option value="2">Credit Card</option>
</select>
</div>
</div>
<div class="row">
<input type="submit" value="Update">
</div>
</form>
JavaScript - I doubt the issue is here as the parameters are passed when viewing the network tab in Google dev tools (see screenshot below).
/*When icon edit icon is clicked, set readOnly/disabled values to false and input/icon colors to appropriate colors*/
$( "#editIcon" ).click(function() {
console.log("Edit called.")
if(!clicked){
$( "#name" ).prop('readonly', false)
$( "#street" ).prop('readonly', false)
$( "#city" ).prop('readonly', false)
$( "#state" ).prop('disabled', false)
$( "#zip" ).prop('readonly', false)
$( "#paymentType" ).prop('disabled', false)
//Set input color to black
$( "#name" ).css("color", "black")
$( "#street" ).css("color", "black")
$( "#city" ).css("color", "black")
$( "#state" ).css("color", "black")
$( "#zip" ).css("color", "black")
$( "#paymentType" ).css("color", "black")
//Set icon to red
$("#editIcon").css("color", "red")
clicked = true;
} else{
$( "#name" ).prop('readonly', true)
$( "#street" ).prop('readonly', true)
$( "#city" ).prop('readonly', true)
$( "#state" ).prop('disabled', true)
$( "#zip" ).prop('readonly', true)
$( "#paymentType" ).prop('disabled', true)
//Set input color to black
$( "#name" ).css("color", "gray")
$( "#street" ).css("color", "gray")
$( "#city" ).css("color", "gray")
$( "#state" ).css("color", "gray")
$( "#zip" ).css("color", "gray")
$( "#paymentType" ).css("color", "gray")
//Set icon to red
$("#editIcon").css("color", "#7543b7")
clicked = false;
}
});
Update Action in Contractor Controller
def update(Long id){
println("I made it to update for Contractors")
def contractorInstance = Contractor.get(id)
contractorInstance.properties = params
println contractorInstance.validate()
println contractorInstance.errors
if(!contractorInstance.save()){
println 'Contractor did not update.'
} else{
println 'Contractor updated.'
}
println contractorInstance.id //prints id to console
println contractorInstance.name //prints updated name to console
redirect(action: "index")
}
Development Data Source in Application.yml
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
logsql: true #added by PCB on 5/14
Dev Tools Screenshot - Form Data Post
Contractor Domain
class Contractor {
String name
String street
String city
String state
String zip
PaymentType paymentType
static hasMany = [masteragreements: MasterAgreement, contracts: Contract, termsAndConditions: TermsAndConditions]
static constraints = {
}
}
EDIT: I'm using Grails Version 4.0.3
A Transaction is required to write to the database in Grails 4/Hibernate 5.2+. In your case you are writing to a session but never instructing that session to be flushed(written) to the database. That happens at the end of a transaction or when flush is explicitly called.
The most common solution would be to move the logic to a Service and annotate the method with #Transactional or using GORM Data Services as they manage transactions for you.
One of the ways you can force the flush (and view your errors) is to do it something like this:
if(!instance.save(flush: true)){
instance.errors.allErrors.each { println it }
}
I have created a master page for my application and then the master application has been displayed in every page, but I have created a content page and I have created a separate CSS style design for this page and I have called to that particular page but the style for this page is not displayed.
#model MedeilMVC_CLOUD.Models.Company
#{
ViewBag.Title = "Add Company";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="~/css/separate/vendor/jquery-steps.min.css" rel="stylesheet" />
<div class="page-content">
<div class="container-fluid">
<section class="box-typical box-panel mb-4">
<header class="box-typical-header">
<div class="tbl-row">
<div class="tbl-cell tbl-cell-title">
<h3>Form steps example</h3>
</div>
</div>
</header>
<div class="box-typical-body">
<form id="example-form" action="#" class="form-wizard">
<div>
<h3>Account</h3>
<section>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email" required>
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Confirm Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
</section>
<h3>Profile</h3>
<section>
<div class="form-group">
<label for="exampleInputEmail1">Address</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter text" required>
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
</section>
<h3>Hints</h3>
<section>
<ul>
<li>Foo</li>
<li>Bar</li>
<li>Foobar</li>
</ul>
</section>
<h3>Finish</h3>
<section>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" id="agree" class="required" required>
<label for="agree">Terms and Conditions</label>
</div>
</div>
</section>
</div>
</form>
</div><!--.box-typical-body-->
</section>
</div>
</div>
<script src="~/js/lib/jquery-validation/jquery.validate.min.js"></script>
<script src="~/js/lib/jquery-steps/jquery.steps.min.js"></script>
<script>
$(function () {
$("#example-basic ").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
autoFocus: true
});
var form = $("#example-form");
form.validate({
rules: {
agree: {
required: true
}
},
errorPlacement: function errorPlacement(error, element) { element.closest('.form-group').find('.form-control').after(error); },
highlight: function (element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function (element) {
$(element).closest('.form-group').removeClass('has-error');
}
});
form.children("div").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
onStepChanging: function (event, currentIndex, newIndex) {
form.validate().settings.ignore = ":disabled,:hidden";
return form.valid();
},
onFinishing: function (event, currentIndex) {
form.validate().settings.ignore = ":disabled";
return form.valid();
},
onFinished: function (event, currentIndex) {
alert("Submitted!");
}
});
$("#example-tabs").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
enableFinishButton: false,
enablePagination: false,
enableAllSteps: true,
titleTemplate: "#title#",
cssClass: "tabcontrol"
});
$("#example-vertical").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
stepsOrientation: "vertical"
});
});
</script>
Style Sheet Link
<link href="~/css/separate/vendor/jquery-steps.min.css" rel="stylesheet" />
And also javascript file also not working
you can use section directive in layout.
In layout write in that place where you want insert section (head/fooret etc...)
#RenderSection("styles", false)
Then in view set the content to this section:
#section styles{
<link href="~/css/separate/vendor/jquery-steps.min.css" rel="stylesheet" />
}
Name of this section may be any. But in view you can use each section only one time in any place.
I want to add a project name and task name while clicking on a particular date in fullcalendar but I don't know how to use bootbox.prompt or bootbox.dialog with more than one fields so can you help me out?
select: function (start, end, allDay) {
debugger;
bootbox.prompt("Add New Event", function (title) {
debugger;
if (title !== null) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay,
className: 'label-info'
},
true // make the event "stick"
);
}
});
It's quite simple, we can use bootbox dialog for that
bootbox.dialog({
title: 'Add New Event',
message: $('#form'),
show: false,
}).on("shown.bs.modal", function (e) {
$('#form').show()
}).on('hide.bs.modal', function (e) {
/**
* Bootbox will remove the modal (including the body which contains the login form)
* after hiding the modal
* Therefor, we need to backup the form
*/
$('#form').hide().appendTo('body');
})
.modal('show');
calendar.fullCalendar('unselect');
}
In html
<form id="form" method="post" class="form-horizontal" style="display: none;">
<div class="form-group">
<label class="col-xs-3 control-label">Username</label>
<div class="col-xs-5">
<input type="text" class="form-control" name="username" />
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label">Password</label>
<div class="col-xs-5">
<input type="password" class="form-control" name="password" />
</div>
</div>
<div class="form-group">
<div class="col-xs-5 col-xs-offset-3">
<button type="submit" class="btn btn-primary" style="float:right;">Login</button>
</div>
</div>
I'm having a problem with my GET request to API, here is:
self.search = {
init_date: new Date(),
end_date: new Date(),
statuses: {"Aberto": false, "Em andamento": false, "Fechado": false},
district: null,
address: null,
tags: null
};
$http.get(apiUrl + requestEndpoint + 'search', {params: self.search}).then(function(response){
self.gridOptions.data = response.data;
});
So, what is happening is that my params in API looks like this
{"end_date"=>"2016-07-07T22:58:11.943Z",
"init_date"=>"2016-07-07T22:58:11.943Z",
"statuses"=>"{\"Aberto\":false,\"Em andamento\":false,\"Fechado\":false}",
"format"=>:json,
"controller"=>"api/v1/requests",
"action"=>"search"}
and then I cannot read the statuses because it's a kind of string. How should I solve that?
Just to know... My Statuses value come from form in HTML with checkboxes
<div class="form-group">
<h5>Status</h5>
<div class="col-sm-12">
<input type="checkbox" name="status" id="aberto" class="k-checkbox" value="Aberto" ng-model="reportsCtrl.search.statuses['Aberto']">
<label class="k-checkbox-label" for="aberto"> Aberto </label>
<input type="checkbox" name="status" id="em-andamento" class="k-checkbox" value="Em andamento" ng-model="reportsCtrl.search.statuses['Em andamento']">
<label class="k-checkbox-label" for="em-andamento"> Em andamento </label>
<input type="checkbox" name="status" id="fechado" class="k-checkbox" value="Fechado" ng-model="reportsCtrl.search.statuses['Fechado']">
<label class="k-checkbox-label" for="fechado"> Fechado </label>
</div>
</div>
PS: My API is Rails
Regards.
i have a search form whith jquery autocomplete on some fields.
<form id="prjs_form" class="prjcts" action="<wp:action path="/ExtStr2/do/enpim/projects/list.action" />" method="post">
<div class="row bord">
<div class="wid_ut">
<span class="label"><wp:i18n key="ACRONYM" /></span>
<span class="field"><input id="autAcronym" type="text" name="bean.acronym" value="${bean.acronym}" class="lrg autocomplete" /></span>
</div>
......................
<div class="row">
<div class="act_btns">
<input type="submit" name="search" value="<wp:i18n key='SEARCH'/>">
</div>
</div>
</form>
My need is to submit the form when I select one of the values ​​suggested by autocomplete.
this is my jquery
jQuery('#autAcronym').autocomplete({
params: { type: 'project_acronym' },
paramName: 'text',
serviceUrl: '<wp:info key="systemParam" paramName="applicationBaseURL" />json/hall.ShowParameters',
minChars: 2,
select: function(event, ui) {
if(ui.item){
$(event.target).val(ui.item.value);
}
$('#prjs_form').submit();
return false;
}
});
when i start typing on field the autocomplete work fine, but when i select one of the suggested value the select event doesn't trigger....
what's wrong?
the other similar post on stackoverflow doesn't solved my problem
thanks in advance