Giáo án link (giaoan.link) chia sẻ đến các bạn một project mới về Google sheet App script Webapp “Data Entry Form with Tag Select Input”. Với project này, trên form web app nhập liệu sẽ có một trường lựa chọn dạng kiểu tag, bạn có thể chọn nhiều tag một lần và có thể xóa bỏ từng tag khi cần. Dưới đây là code app script và video hướng dẫn và demo.
Xem thêm nhiều project google sheet, app script tại đây: Click mở danh sách project
Xem các bài tập excel ứng dụng:
- VBA Excel Xây dựng hàm chuyển chuỗi có dấu thành không dấu, khoản trắng thành dấu –
- Google sheet Webapp | Lấy dữ liệu trên Sheet hiển thị dạng Bảng có phân trang trùy chọn trên website
- Web App Script | Trang trắc nghiệm online hỗ trợ hình ảnh, lưu file kết quả – Form nhập bộ câu hỏi
- Google sheet Webapp Quản lý Lịch dạy học giáo viên trong trung tâm-Lọc theo Tên-Lớp-Khung giờ -Môn
- Google sheet webapp | CRUD FORM – ĐIỀN THÔNG TIN TỪ FORM VÀO TEMPLATE GOOGLE DOC, KÈM HÌNH ẢNH 1
- Google sheet webapp | Dropdown phụ thuộc – Truy xuất Spreadsheet và các Sheet phụ thuộc từ Folder
- Tạo hóa đơn trên Google sheet – Gửi email đính kèm hóa đơn pdf – Quản lý url hóa đơn trên danh sách
- Google sheet Ứng dụng theo dõi đơn hàng – Danh sách sản phẩm mua, trạng thái đơn hàng
- Tip on Ms Word Hướng dẫn tạo ngắt trang, xóa ngắt trang đơn lẽ hoặc toàn bộ ngắt trang trên file doc
- Google sheet | Generate QR Codes – Mã hóa nội dung Cell – Thêm hình ở giữa mã QR code
Code của file “Code.gs”
function doGet() {
return HtmlService.createTemplateFromFile('index').evaluate()
.setTitle('Youtube.com/Netmediacctv')
.addMetaTag('viewport','width=device-width , initial-scale=1')
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
}
function saveData(obj){
let ss = SpreadsheetApp.getActive().getSheetByName('data')
ss.appendRow([obj.fname,
[obj.hobby].join()
])
return obj
}
Code của file “index.html”
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.rtl.min.css" />
<style>
@import url('https://fonts.googleapis.com/css2?family=Kanit&display=swap');
*{
font-family: "Tahoma", sans-serif;
font-weight: 400;
font-style: normal;
}
</style>
</head>
<body>
<div class="container">
<div class="col-md-6 mx-auto">
<form id="myForm" onsubmit="saveData(this)">
<div class="col-md-12 mb-2">
<label>Họ và tên</label>
<input type="text" class="form-control" name="fname" required>
</div>
<div class="col-md-12 mb-2">
<label>Sở thích của bạn</label>
<select class="form-select" id="hobby" name="hobby" data-placeholder="Chọn..." multiple required>
<optgroup label="Thể loại phim">
<option>Phim hành động</option>
<option>Phim tình cảm</option>
<option>Phim hoạt hình</option>
<option>Phim kinh dị</option>
</optgroup>
<optgroup label="Thể thao">
<option>Bóng đá</option>
<option>Cầu lông</option>
<option>Chạy bộ</option>
</optgroup>
<optgroup label="Màu sắc">
<option>Xanh </option>
<option>Vàng</option>
<option>Tím</option>
<option>Cam</option>
</optgroup>
</select>
</div>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
</div>
</div>
<script>
window.onload = ()=>{
// For Select2 4.1
$("#hobby").select2({
theme: "bootstrap-5",
});
}
function saveData(obj){
event.preventDefault()
Swal.fire({
title: "Loading.."
});
Swal.showLoading();
google.script.run.withSuccessHandler(data=>{
console.log(data)
Swal.fire({
position: "top",
icon: "success",
title: "Success",
showConfirmButton: false,
timer: 1500
});
document.getElementById('myForm').reset()
$('#hobby').val(null).trigger('change');
}).saveData(obj)
}
</script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.0/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
</body>
</html>