HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="wrapper">
<!-- INPUTS -->
<div class="row purchase-row">
<div class="col-lg-4">
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<i class="fas fa-dolly"></i>
</span>
</div>
<select class="form-control product select2 js-programmatic-init" name="pro-product" id="id_pro-product">
<option value="0" selected disabled>--- Product Name ---</option>
{% for obj in products %}
<option value="{{obj.id}}">{{obj.name}}</option>
{% endfor %}
</select>
</div>
</div>
</div>
<div class="col-lg-1">
<div class="form-group ">
<div class="input-group">
<select class="form-control unit" name="pro-unit" id="id_pro-unit">
<option disabled selected>---Unit---</option>
</select>
</div>
</div>
</div>
<div class="col-lg-1">
<div class="form-group ">
<div class="input-group">
{% render_field pro_form.quantity class="form-control quantity" %}
</div>
</div>
</div>
<div class="col-lg-1">
<div class="form-group ">
<div class="input-group">
{% render_field pro_form.last_price class="form-control last-price" %}
</div>
</div>
</div>
<div class="col-lg-1">
<div class="form-group ">
<div class="input-group">
{% render_field pro_form.purchasing_price class="form-control purchasing-price" %}
</div>
</div>
</div>
<div class="col-lg-1">
<div class="form-group ">
<div class="input-group">
{% render_field pro_form.total class="form-control total" %}
</div>
</div>
</div>
<!-- BUTTONS -->
<div class="col-lg-1">
<div class="control ">
<button type="button" id="clone_vendor" class="btn btn-outline-danger purchase-minus remove_item btn-block" style="margin-bottom: 20px;">
<span class="fas fa-times"></span>
</button>
</div>
</div>
<div class="col-lg-1">
<div class="control ">
<button type="button" id="" class="btn btn-outline-secondary purchase-broom btn-block" style="margin-bottom: 20px;">
<span class="fas fa-broom"></span>
</button>
</div>
</div>
<div class="col-lg-1">
<div class="control ">
<button type="button" id="" class="btn btn-outline-info purchase-eye btn-block" style="margin-bottom: 20px;">
<span class="fas fa-eye"></span>
</button>
</div>
</div>
</div>
<!-- ./ROW -->
<div class="row">
<div class="col-lg-4">
<label class="btn bg-gradient-lightblue btn-block btn-sm">Product </label>
</div>
<div class="col-lg-1">
<label class="btn bg-gradient-lightblue btn-block btn-sm">Unit </label>
</div>
<div class="col-lg-1">
<label class="btn bg-gradient-lightblue btn-block btn-sm">Quantity </label>
</div>
<div class="col-lg-1">
<label class="btn bg-gradient-lightblue btn-block btn-sm">Last Pr </label>
</div>
<div class="col-lg-1">
<label class="btn bg-gradient-lightblue btn-block btn-sm">Price </label>
</div>
<div class="col-lg-1">
<label class="btn bg-gradient-lightblue btn-block btn-sm">Total</label>
</div>
<div class="col-lg-3">
<label class="btn bg-gradient-lightblue btn-block btn-sm">
Tools
</label>
</div>
</div>
<br>
<button type="button" id="clone_purchase_product" class="btn btn-outline-primary purchase-plus add_item" style="margin-bottom: 20px;">
<span class="fas fa-caret-down"></span>
</button>
<!-- ADDING BUTTON -->
<!-- <div class="row add-row">
<div class="col-sm-1">
<div class="control ">
<button
type="button"
id="clone_purchase_product"
class="btn btn-outline-primary purchase-plus add_item"
style="margin-bottom: 20px;"
>
<span class="fas fa-caret-down"></span>
</button>
</div>
</div>
</div> -->
</div>
<script>
$(document).ready(function() {
var purchase = $('.purchase-row').last().clone();
let purchaseCount = 0;
$(document).on('click', '.add_item', function() {
// $(".select2").select2();
var clone = purchase.clone(); //.prop('id', 'product_' + purchaseCount);
// var clone = purchase.clone().prop('class', 'product_' + purchaseCount);
console.log('clone: ', clone);
$(this).prevAll('.purchase-row').first().after(clone.hide());
clone.slideDown('fast');
// $('#product_'+ purchaseCount).find('#id_pro-product').removeClass('product').addClass('newProduct');
// $('#product_'+ purchaseCount).find('#id_pro-unit').removeClass('unit').addClass('newUnit');
$('.purchase-row').find('#id_pro-product').removeClass('product').addClass('newProduct');
$('.purchase-row').find('#id_pro-unit').removeClass('unit').addClass('newUnit');
$('.purchase-row').find('#id_pro-product').addClass('product_'+ purchaseCount);
$('.purchase-row').find('#id_pro-unit').addClass('unit_'+ purchaseCount);
// Bind an event
// $('.newProduct').on('select2:select', function (e) {
// console.log('select event');
// });
// The next code for reinitialize select2
// var $example = $(".js-programmatic-init").select2();
var $example = $(".newProduct").select2();
$example.select2();
// ($(".newProduct").select2().select2());
// $(".js-programmatic-init").select2();
// $('.purchase-row').find('.product').addClass('newProduct');
// $('.purchase-row').find('.unit').addClass('newUnit');
purchaseCount++;
console.log('PURCHASE-COUNT: ', purchaseCount);// $(this).parent().slideUp('fast');
});
$(document).on('click', '.purchase-minus', function() {
if (purchaseCount == 0) {
// Do nothing.
alert('You can not delete this row' );
} else {
$(this).closest('.purchase-row').remove();
purchaseCount--;
console.log('PURCHASE-COUNT2: ', purchaseCount);// $(this).parent().slideUp('fast');2
}
});
$(document).on('click', '.purchase-broom', function() {
// $(this).closest('.purchase-row').find('select').val(0);
$(this).closest('.newProduct').select2('destroy');
$(this).closest('.purchase-row').find('select')[0].selectedIndex=0;
// $(this).closest('.purchase-row').find('input').val('');
});
$(document).on('change', '.product', function(e){
var product_id = $(this).val();
console.log('SUCCESS-CHANGE-PRODUCT: ', product_id);
$.ajax({
type: 'POST',
url: '{% url "purchases:get_product_unit" %}',
// dataType: 'json',
// async: true,
// cache: false,
data: {
'pro-product': $('.purchase-row select').closest('.product').val(), // this is right
// find('#id_pro-product')
},
success: function (data) {
console.log(
'FROM SUCCESS: ', data['unit'],
);
var values_3 = data['unit'];
// $('#id_pro-unit').text('');
// $('select').closest('.unit').find('select').text('');
$('select').closest('.unit').text('');
if (values_3.length > 0) {
for (var i = 0; i < values_3.length; i++) {
// $('#id_pro-unit').append('<option>' + values_3[i] + '</option>');
$('select').closest('#id_pro-unit').append('<option>' + values_3[i] + '</option>');
}
}
},
error: function (){
console.log('ERROR with ajax request in Adding Purchase !!!');
},
});
e.preventDefault();
});
$(document).on('change', '.newProduct', function(e){
var product_id = $(this).val();
var $this = $(this);
// $('select').find('#id_pro-product').addClass('product_'+ product_id + '_' + purchaseCount);
// $('select').find('#id_pro-unit').addClass('unit_'+ product_id + '_' + purchaseCount);
console.log('SUCCESS-CHANGE-PRODUCT-FROM-NEW-CLASS: ', product_id);
$.ajax({
type: 'POST',
url: '{% url "purchases:get_new_row_unit" %}',
// dataType: 'json',
// async: true,
// cache: false,
data: {
'pro-product': product_id,
// $('#product_'+purchaseCount).closest('.newProduct select').val(),
// find('#id_pro-product')
},
success: function (data) {
console.log(
'FROM SUCCESS-NEW-CLASS: ', data['unit'],
'PRODUCT-FROM-NEW-CLASS: ', data['product'],
);
var values_3 = data['unit'];
// $('#id_pro-unit').text('');
$('select').closest('.unit_'+purchaseCount).text('');
if (values_3.length > 0) {
for (var i = 0; i < values_3.length; i++) {
$('.purchase-row select').closest('.unit_'+ purchaseCount).append('<option>' + values_3[i] + '</option>');
// $('.newUnit select').closest('#product_'+ purchaseCount).append('<option>' + values_3[i] + '</option>');
// $('select').closest('#product_'+ purchaseCount).find('.newUnit').append('<option>' + values_3[i] + '</option>');
// $('.newUnit select').closest('.unit_'+purchaseCount).append('<option>' + values_3[i] + '</option>');
}
}
},
error: function (){
console.log('ERROR with ajax request in Adding Purchase-New Class !!!');
},
});
e.preventDefault();
});
});
</script>
Also see: Tab Triggers