I'm trying to render the rows of a table where each row is my custom component <todo-list>, but the resulting rows get rendered outside of my table. Why is this?
Here's a screenshot of the DOM tree which shows what is happening:
My view:
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Dashboard</div>
<div class="panel-body">
<div id="appTest">
<div>#{{error}}</div>
<table class="table-responsive">
<todo-list
v-for="todo in todos"
v-bind:todo-obj="todo"
v-bind:key="todo.id"
:todo-obj.sync="todo"
v-on:usun="deleteTod"
></todo-list>
</table>
<div v-if="isLogged" id="todoText">
<textarea v-model="todoText" cols="53" rows="5"></textarea>
<div id="addButton">
<button v-on:click="addTodo" class="btn btn-success" >Add to do</button>
</div>
</div>
<div v-else>
You have to be
Login
to add new todos
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And here is my component:
Vue.component('todoList', {
props: ['todoObj'],
template: '<tr>' +
'<td><div class="round"><input id="todoObj.id" type="checkbox" v-on:click="toggle" v-model="todoObj.done" /><label for="todoObj.id"></label></div></td>' +
'<td class="textTodo">{{todoObj.description}}</td>' +
'<td><button v-on:click="deleteTodo" class="btn-xs btn-danger">delete</button></td>' +
'</tr>',
Also my checkboxes are not working. They look fine, but they don't toggle when I click them, they only react when checking the first row from the table. Why?
Your table might not be rendering correctly due to DOM Template Parsing Caveats. Try this instead:
<table class="table-responsive">
<tr
v-for="todo in todos"
is="todo-list"
:todo-obj="todo"
:key="todo.id"
#usun="deleteTod"
></tr>
</table>
Also you had the todoObj bound twice (I removed the .sync one in the above code).
As for the checkbox issue, I'm not completely sure on what the problem is, especially since you have not provided the code for the component (a fiddle would be great). Why do you have #toggle and v-model? Couldn't you just use v-model? You also forgot to v-bind to the checkbox's id attribute: id="todoObj.id" (is that necessary anyway?).
Related
I'm working with asp.net core mvc and I have two views, one to edit a profile and another to show the profile. The view to edit the profile has checkboxes and the view to show the profile has a list with the items that got selected in the edit view. Whenever I edit the profile, all the checkboxes are unselected. I want that whenever I'm on the EditProfile view, the items that were on the ShowProfile view get selected and the others unselected. If I select a checkbox, that item gets added to the list and if I unselect a previous selected item, that item gets removed from the list. Since I'm a beginner, I have no idea how to do this working with both views. I did multiple things and it didn't work
Part of the ShowProfile view
#model ModifyProfile
#{
}
<div class="card">
<div class="card-body">
<a class="btn btn primary"href="\ProfileDetails\EditProfile">Edit</a>
</div>
</div>
<div class="card-body">
<h3 class="mb-3">Interests</h3>
<div class="mb-3">
<div class="text">Interests:</div>
#if (Model.InterestProfile != null){
<ul>
#foreach(InterestProfile interestProfile in Model.InterestProfiles{
<li class="mb-3">
#interestProfile.Interest.InterestName
</li>
}
</ul>
}else
{
#:No interests
}
</div>
</div>
Part of the EditProfileView
#model ProfileViewModel
#{
}
<form action="EditProfile" method="post">
<div class="card">
<div class="card-body">
<button class="btn btn-primary" type="submit">Submit changes</button>
</div>
</div>
<div class="card">
<div class="card-body">
<div>
<label class="form-label">Interested in</label>
<div class="checkbox">
#foreach (Interest interest in Model.Interests)
{
<label><input type="checkbox" name="interestId" value="#interest.InterestId">
#interest.InterestName </label>
}
</div>
</div>
</div>
</div>
Is there a way to do it with checkboxes? I think that a dropdown list could be helpful here but I don't know if it's worth deleting all the code I have already to make that change
I recently ran into some problems when trying to use the Materialize modal and dropdown features with Blaze, specifically when there are multiple instances of each.
I have this template called cadcall:
<template name="cadcall">
<tr>
<td class="truncate">{{id}}</td>
<td>FRI</td>
<td>{{time}}</td>
<td>{{type}}</td>
<td>{{location}}</td>
<td>{{notes}}</td>
<td>
<i class="material-icons call-dropdown-button" data-activates="cadcallactions">more_vert</i>
</td>
</tr>
<div id="call-details-modal" class="modal">
<div class="modal-content">
<h4>Call Details</h4>
<div class="row">
<form class="new-call col s12">
<div class="row">
<div class="input-field col s6">
<input id="call-id" type="text" class="validate" disabled>
<label for="call-id">ID</label>
</div>
<div class="input-field col s6">
<input id="call-time" type="text" class="validate" disabled>
<label for="call-time">Time</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="call-location" type="text" autocomplete="off">
<label for="call-location">Location</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<textarea id="call-notes" class="materialize-textarea" length="100000" autocomplete="off"></textarea>
<label for="call-notes">Notes</label>
</div>
</div>
<div class="modal-footer">
<button type="submit" href="#!" class="modal-action modal-close waves-effect waves-grey btn-flat center">Submit</button>
</div>
</form>
</div>
</div>
</div>
<ul id='cadcallactions' class='dropdown-content'>
<li><a class="callupdate" href=""><i class="material-icons">update</i>Update</a></li>
<li><a class="callresolve" href=""><i class="material-icons">check</i>Resolve</a></li>
</ul>
</template>
Here is the cadcall events:
Template.cadcall.events({
'click .callresolve'(e) {
Calls.remove(this._id);
},
});
Here is the cadcall onRendered:
Template.cadcall.onRendered(function() {
$(document).ready(function () {
$('.call-details').leanModal();
});
$('.call-dropdown-button').dropdown({
inDuration: 300,
outDuration: 225,
constrainWidth: false, // Does not change width of dropdown to that of the activator
hover: false, // Activate on hover
gutter: 0, // Spacing from edge
belowOrigin: true, // Displays dropdown below the button
alignment: 'right', // Displays dropdown with edge aligned to the left of button
stopPropagation: false // Stops event propagation
});
});
Essentially, for each call there is in the Mongo database, I iterate each call entry. However, if there are multiple calls, the modal doesn't function correctly. If I try to close the modal (by clicking the class callupdate after opening it, the gray area behind it stays.
In addition to the modal not working correctly, the dropdown menu also acts funky, specifically when I try to delete a field (by clicking the class callresolve). Whenever I try to delete a call entry it works, but thereafter the dropdown menus on the other call entries stop working altogether. Furthermore, for some reason when I add an entry then delete it, an error pops up in the Chrome console:
blaze.js:650 Uncaught Error: Must be attached
at Blaze._DOMRange.DOMRange.containsElement (blaze.js:650)
at Blaze._DOMRange.<anonymous> (blaze.js:2612)
at HTMLAnchorElement.<anonymous> (blaze.js:863)
at HTMLTableSectionElement.dispatch (jquery.js:4723)
at HTMLTableSectionElement.elemData.handle (jquery.js:4391)
Presumably, since these problems only occur when I have multiple call entries, I think the HTML may be conflicting with each iteration of the call entry. Is there a way to remedy this issue?
I have a form within modal and I don't seem to be able to catch the submit event.
Let's say we have a html page defined as (for the sake of simplicity leaving out any templates defined by me)
<body>
<button class="ui button">Open modal</button>
<div class="ui small modal">
<div class="header">
Enter your email
</div>
<div class="content">
<form class="ui form">
<div class="field">
<div class="ui left icon input">
<i class="at icon"></i>
<input type="email" name="email" placeholder="Email">
</div>
</div>
<div class="ui error message">
</div>
</form>
</div>
<div class="actions">
<div class="ui negative button">
Cancel
</div>
<div class="ui positive primary loadable button">
Reset password
</div>
</div>
</div>
</body>
and registred template events
Template.body.events({
'click button': function () {
$('.modal').modal('show');
},
'submit form': function () {
alert('called');
}
});
When I submit the form it doesn't get cought by the handler. Why and what's the best approach?
I got something similar working by defining the inner content of modal as template, but it makes things much harder. Is there any other way?
EDIT: Here's meteorpad that demostrates the issue
The reason behind this behavior is that modal is detached from the DOM. This behavior can be overriden by setting detachable: false
Here's working meteorpad
Credits
I know similar questions have been asked earlier, but I have tried them and they aren't working. I have a dialog box, with some text and a button, which I need to position in the center of the box. My HTML is given below:
<div id='step3' class='item'>
<div class='row span9'>
<div class="text center"><button id='loginButton' class='btn btn-success' onClick='window.location.reload()'>Login again</button></div>
<small>using your new credentials.</small>
</div>
</div>
I tried placing the button inside a div and used <div style="text-align:center"> but it didn't work. Does anyone know how I could place the button in the center, preferably without adding an external CSS class?
Your class="text center" should be class="text-center", and you also don't need the row tag (it breaks the responsiveness).
<div id="step3" class="item">
<div class="span12">
<div class="text-center">
<button id="loginButton" class="btn btn-success" onClick="window.location.reload()">Login again</button>
<br> <small>using your new credentials.</small>
</div>
</div>
Also you have single quotes '' on most of your markup. Keep in mind this is with an old version of Bootstrap so depending on how wide the viewport is it might not be perfectly center.
I suppose it's wrong to nest a col-md-x immediately inside a col-md-x in Bootstrap 3. Am I right?
I have following at the moment:
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<div class="row">
<input class="col-md-4" value="something" />
<div class="col-md-8">Something here</div>
</div>
In this case, the input border starts at the very beginning of the row. It doesn't have any padding on the outside of it.
I would like the input to show 15px away from the row border. The way I know of how to achieve this is to put this input inside a col-md-x. However, could this cause any issues?
From the bootstrap docs:
To nest your content with the default grid, add a new .row and set of
.col-sm-* columns within an existing .col-sm-* column.
So as long as you are nesting within child rows, you are gonna be fine. Another option would be custom css rules and ids for your nested structure to achieve the desired padding or margin.
UPDATE
To refer to your comment, since this is about validation states: let me add that bootstrap already offers great validation-highlighting. See this quick sample. The bootstrap docs on forms offer great documentation on this topic. As for the padding: I like to put most of my "not-inline" forms into a .well, which shows the user, where action is required and allows a consistent styling of forms...
var resetSec = function(){
$('#sth-form-section').removeClass('has-error');
$('#sth-form-section').removeClass('has-warning');
$('#sth-form-section').removeClass('has-success');
$('#helpBlock-sth').addClass('sr-only');
$('#helpBlock-sth').html('');
};
$('#invalid').click(function(){
resetSec();
$('#sth-form-section').addClass('has-error');
$('#helpBlock-sth').removeClass('sr-only');
$('#helpBlock-sth').html('Oh snap! Better think about this one more time!');
});
$('#valid').click(function(){
resetSec();
$('#sth-form-section').addClass('has-success');
$('#helpBlock-sth').removeClass('sr-only');
$('#helpBlock-sth').html('Well done! I think your input was the best so far!');
});
$('#reset').click(function(){
resetSec();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="well">
<form class="form-horizontal" role="form">
<div id="sth-form-section" class="form-group">
<label for="something" class="col-lg-2 control-label">Something:</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="something" placeholder="Something here">
<span id="helpBlock-sth" class="help-block sr-only"></span>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
<button class="btn btn-primary" id="reset">Reset</button>
<button class="btn btn-danger" id="invalid">Invalid</button>
<button class="btn btn-success" id="valid">Valid</button>
Ah, just write the markup a little differently, like so:
<div class="row">
<div class="col-md-4">
<input class="form-control" value="something" />
</div>
<div class="col-md-8">
<p class="form-control-static">Something here</p>
</div>
</div>
The problem was putting the col-md-4 class on the input.