I am using collections2 and meteor-cfs-autoform for schemas and to upload and display image using cfs:gridfs storage adaptor package but unable to show images in template.Can you please tell me where i am doing mistake and its solution.
collections.js
Recipes = new Mongo.Collection('recipes');
Reviews = new Mongo.Collection('reviews');
RecipesImages = new FS.Collection("recipesImages", {
stores: [new FS.Store.GridFS("recipesImages")]
});
RecipesImages.allow({
insert: function(userId, doc) {
return true;
},
update: function(userId, doc, fieldNames, modifier) {
return true;
},
download: function(userId) {
return true;
},
fetch: null
});
Recipes.attachSchema(new SimpleSchema({
name: {
type: String,
label: "Recipe Name",
max: 100
},
ingredients: {
type: [Object],
minCount: 1
},
"ingredients.$.name": {
type: String
},
"ingredients.$.amount": {
type: String
},
description: {
type: String,
label: "How to prepare ",
},
time: {
type: Number,
label: "Time (Minutes)",
},
image: {
type: String,
autoform: {
afFieldInput: {
type: "cfs-file",
collection: 'recipesImages',
label: 'Recipe Picture'
}
}
}
}));
recipes.js
Template.recipes.helpers({
'showRecipes':function(){
return Recipes.find();
},
'images': function () {
return RecipesImages.findOne({_id:id}) ;
}
})
recipes.html
<template name="recipes">
{{#each showRecipes}}
<div class=" col-md-4">
<div class="panel panel-default mb " >
<div class="panel-image">
<img src="{{this.url }}" class="panel-image-preview" />
</div>
<div class="panel-body">
<h4>{{name}}</h4>
<p>{{description}}</p>
</div>
<div class="panel-footer text-center" >
<p>its footer </p>
</div>
</div>
</div>
{{/each}}
</template>
Are you importing cfs:ui? If not, you should include it so that you can use the FS.GetFile helper. Then you can use this code.
Recipes Template
<template name="recipes">
{{#each showRecipes}}
<div class=" col-md-4">
<div class="panel panel-default mb " >
<div class="panel-image">
{{#with FS.GetFile "recipesImages" image}}
<img src="{{url}}" class="panel-image-preview" />
{{/with}}
</div>
<div class="panel-body">
<h4>{{name}}</h4>
<p>{{description}}</p>
</div>
<div class="panel-footer text-center" >
<span class="glyphicon glyphicon-open-file"></span>
</span><small> {{time}}</small>
<span class="glyphicon glyphicon-heart likes" style="vertical-align:middle"></span><small>2 </small>
<span class="glyphicon glyphicon-share"></span>
</div>
</div>
</div>
{{/each}}
</template>
Recipes helpers
Template.recipes.helpers({
'showRecipes':function(){
return Recipes.find();
}
});
Here's the link to cfs:ui documentation
Related
I'm new to Composition API and I don't know why I get http response 400. Payload in request looks same as json object. I have to send to an api a nested object. JSON object looks like this:
{
"contact": {
"email": "",
"firstname": "",
"lastname": "",
},
"description": "",
"preference": "",
"title": "",
"hobbies": [],
"maxSum": -17692428,
"minSum": 98485775,
"interests": [
{
"interest1": ""
},
{
"intereest2": ""
}
],
"passions": [
{
"pasion1": ""
},
{
"passion2": ""
}
]
}
My template is:
<template>
<form class="form" novalidate="">
<div class="form__header">
<h3 class="form__title">Title</h3>
</div>
<div class="form__section">
<label for="title">Title*</label>
<input
type="text"
v-model="title"
/>
</div>
<div class="form__section">
<label for="preference"> Preference*</label>
<textarea
type="text"
v-model="preference"
/>
</div>
<div class="form__section">
<label for="hobbies"> Programming languages*</label>
<textarea
type="text"
v-model="hobbies"
/>
</div>
<div class="form__section">
<label for="interests"> interests*</label>
<textarea
type="text"
v-model="interests"
/>
</div>
<div class="form__section">
<label for="passions"> passions*</label>
<textarea
type="text"
v-model="passions"
/>
</div>
<div class="form__section">
<div> Job mobility*</div>
<select v-model="preference">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</div>
<div class="form__section">
<label for="minSum"> Minimum Payment *</label>
<input
type="number"
v-model="minSum"
/>
</div>
<div class="form__section">
<label for="maxSum"> Maximum Payment *</label>
<input
type="number"
v-model="maxSum"
/>
</div>
<div class="form__section">
<label for="name"> name*</label>
<input
type="text"
placeholder=" Name"
v-model="contact.firstname"
/>
</div>
<div class="form__section">
<label for="last name"> last name *</label>
<input
type="text"
placeholder=" Last Name"
v-model="contact.lastname"
/>
</div>
<div class="form__section">
<label for="email"> email *</label>
<input
type="email""
placeholder=" Email"
v-model="contact.email"
/>
</div>
<div class="form-buttons">
<div class="form__section">
<button
#click.prevent="save()"
id="save"
class="form__submit"
type="submit"
data-inline="true"
>
Save
</button>
</div>
</div>
</form>
</template>
And script tag:
<script>
import { reactive, toRefs } from "vue";
import { ref } from "vue-demi";
export default {
setup() {
const handleSave = reactive({
title: "",
description: "",
hobbies: [],
passions: [],
interests: [],
description: "",
maxSum: "",
minSum: "",
contact: {}
});
const isSaveAdded = ref(false)
const addSave = async () => {
const body = {}
body.title = handleSave.title
body.description = handleSave.description
body.hobbies = handleSave.hobbies.toString().split(",").map(value => {return {hobby:value }})
body.technologies= handleJob.technologies.toString().split(",").map(value => {return {techName:value }})
body.passions = [handleSave.passions]
body.interests = handleSave.interests
body.maxSum = handleSave.maxSum
body.minSum = handleSave.minSum
body.contact = handleSave.contact
const response = await axios.post("/foo", body,
{
headers: {
///////////////////////
}
});
handleSave.value = response.data;
isSaveAdded.value = true
};
return {
...toRefs(handleSave),
addSave,
isSaveAdded
};
}
};
</script>
Why request is not successful and what should it look like? Thank you
var agg = [
{$group: {
_id: null,
totalPrice: { $sum: "$itemPrice" },
total: {$sum: 1}
}}
];
Idea.aggregate(agg, function(err, logs){
if (err) {
return def.reject(err);
}
console.log(logs);
});
and here it is the template file
{{#each ideas}}
<div class="card card-body mb-2">
<h4>{{title}}</h4>
<p>{{details}}</p>
<a class="btn btn-dark btn-block mb-2" href="/ideas/edit/{{id}}">Edit</a>
<form method="post" action="/ideas/{{id}}?_method=DELETE">
<input type="hidden" name="_method" value="DELETE">
<input type="submit" class="btn btn-danger btn-block" value="Delete">
</form>
</div>
{{else}}
<p>No video ideas listed</p>
{{/each}}
I need to open the data from a .phtml file (gallery.phtml) in a modal popup in Magento2. This is the code used to include modal scripts:
<div>
Click Me
</div>
<script>
require(
[
'jquery',
'Magento_Ui/js/modal/modal'
],
function(
$,
modal
) {
var options = {
type: 'popup',
responsive: true,
innerScroll: true,
content: 'gallery.phtml',
buttons: [{
text: $.mage.__('Continue'),
class: '',
click: function () {
this.closeModal();
}
}]
};
var popup = modal(options, $('#popup-mpdal'));
$("#click-me").on('click',function(){
$("#popup-mpdal").modal("openModal");
});
}
);
</script>
The gallery.phtml file is given below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="popup-mpdal">
<h1> Hi I'm here.... </h1>
</div>
</body>
</html>
But the popup is not coming.
I got the answer:
<div>
Click Me
</div>
<div id="popup-mpdal" >
<?php include ($block->getTemplateFile('Vendor_Module::gallery.phtml')) ?>
</div>
<script>
require(
[
'jquery',
'Magento_Ui/js/modal/modal'
],
function(
$,
modal
) {
var options = {
type: 'popup',
responsive: true,
innerScroll: true,
buttons: [{
text: $.mage.__('Continue'),
class: '',
click: function () {
this.closeModal();
}
}]
};
var popup = modal(options, $('#popup-mpdal'));
$("#click-me").on('click',function(){
$("#popup-mpdal").modal("openModal");
});
}
);
</script>
I have used this in html
<button type="button" class="action" data-trigger="trigger">
<span data-bind="i18n: 'Click Here'"></span>
</button>
<div data-bind="mageInit: {
'Magento_Ui/js/modal/modal':{
'type': 'popup',
'title': 'Popup title',
'trigger': '[data-trigger=trigger]',
'responsive': true,
'buttons': [{
text: 'Submit',
class: 'action'
}]
}}">
<div class="content">
Popup Content
</div>
</div>
I have created a modal dialog using Bootstrap and I'm having a problem with the Modal dialog box not clearing form input fields after the box is closed or after it's submitted.
HTML
<!-- Password Reset Modal -->
<div id="passwModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4>Forgot Password?</h4>
<p>Please enter your registered email address below and a new password will be sent to you.</p>
</div>
<div class="modal-body">
<div id="sent"><!-- Display sent message after password reset -->
<form class="form-horizontal" id="reset">
<div class="control-group">
<label class="control-label" for="Email">Username</label>
<div class="controls">
<input class="input-large" type="email" id="Username" name="Username" placeholder="Email Address">
</div>
</div>
<div class="controls">
<button class="btn btn-inverse" id="close" value="CANCEL" data-dismiss="modal" aria-hidden="true">CLOSE</button>
<button class="btn btn-success" id="submit">SEND</button>
</div>
</form>
</div><!-- end of sent -->
</div>
</div><!-- end of Password Reset Modal -->
JavaScript (Validation & ajax)
$(document).ready(function () {
jQuery.validator.addMethod("accept", function (value, element, param) {
return value.match(new RegExp("." + param + "$")); });
$("#register").validate({
rules: {
FirstName: {
required: true,
accept: "[a-zA-Z]+"
},
LastName: {
required: true,
accept: "[a-zA-Z]+"
},
Pwd: {
required: true,
minlength: 8
},
CPwd: {
required: true,
minlength: 8,
equalTo: "#Pwd"
},
Email: {
required: true,
email: true
},
Agree: "required"
},
messages: {
FirstName: {
required: "First name required.",
accept: "Letters only please."
},
LastName: {
required: "Last name required.",
accept: "Letters only please."
},
Pwd: {
required: "Please create a password.",
minlength: "Password must be at least 8 characters."
},
CPwd: {
required: "Please confirm password.",
minlength: "Password must be at least 8 characters.",
equalTo: "Passwords do not match."
},
Email: "Email address is not valid.",
Agree: "Please accept our policy."
},
submitHandler: function() {
$.ajax({
type: "POST",
url: "../process.php",
data: $('form#register').serialize(),
success: function (msg) {
$("#thanks").html(msg)
},
error: function () {
alert("failure");
}
});
}
});
}); // end document.ready
Just an update to the previous answer for anyone now using the new Bootstrap, currently v3.1.1, that needs this answered!
$('#passwModal').on('hidden.bs.modal', function (e) {
$('#Username').val('');
});
To ensure that your form will be empty when you will reopen the modal, you can do this for every field on your form. It will delete the last value of your field on the hidden state of the modal when this one is closing :
$('#passwModal').on('hidden', function () {
$('#Username').val("");
});
I have a dropdownlist in my page this is the code:
<div id="test">
Role: <span data-bind="text: role"></span>
</br>
Roles:<select id="roles" data-bind="source: roles, value: role" data-text-field="roleName" data-value-field="roleId" ></select>
<ul id="view" data-template="Access-template" data-role="listview" data-bind="source:Accesses"></ul>
<script id="Access-template" type="text/x-kendo-template">
<li>
<input type="checkbox" data-bind="checked: selected" />
<label data-bind="text: AccessName" />
</li>
</script>
</div>
and I want that when I change the dropdownlist value it changes my role collection. This is my code:
var Accesses = [{
AccessName: 'Create',
selected: false
}, {
AccessName: 'Delete',
selected: false
}, {
AccessName: 'Update',
selected: true
}];
var Roles = [{
roleName: "Admin",
roleId: 1,
accessItem: Accesses
}, {
roleName: "User",
roleId: 2,
accessItem: Accesses
}];
var viewModel = kendo.observable({
roles: Roles,
accssesItem: Roles.accessItem
});
kendo.bind($("#test"), viewModel);
Figuring out what DropDown item is selected is a little... unintuitive, but here is what you want:
<script id="Access-template" type="text/x-kendo-template">
<li>
<input type="checkbox" data-bind="checked: selected" />
<label data-bind="text: AccessName" />
</li>
</script>
<select
data-role="dropdownlist"
data-bind="source: roles, events: { select: roleSelected }"
data-text-field="roleName"
data-value-field="roleId"></select>
<ul data-template="Access-template"
data-role="listview"
data-bind="source: accessItem"></ul>
...and...
$(document).ready(function () {
var roles = [{
roleName: "Admin",
roleId: 1,
accessItem: [{
AccessName: 'Create',
selected: true
}, {
AccessName: 'Delete',
selected: true
}, {
AccessName: 'Update',
selected: true
}]
}, {
roleName: "User",
roleId: 2,
accessItem: [{
AccessName: 'Create',
selected: false
}, {
AccessName: 'Delete',
selected: false
}, {
AccessName: 'Update',
selected: true
}]
}];
var viewModel = kendo.observable({
roles: roles,
accessItem: roles[0].accessItem,
roleSelected: function (e) {
this.set("accessItem", this.roles[e.item.index()].accessItem);
}
});
kendo.bind("body", viewModel);
});
Working jsFiddle here: http://jsfiddle.net/rally25rs/JHNm6/